c++14

Qt Forwarding signal/slot connections

蓝咒 提交于 2019-12-24 07:53:20
问题 Let's say SomeClass has members Object1 and Object2 and there is a connection between Object1 and Object2 like: connect(Object1, signal1, Object2, slot1) After some refactoring Object3 was added to SomeClass and Object2 was moved to be a member of Object3 , but still exist the need for the connection between Object1 and Object2 . The communication between Object1 and Object2 will have to go through Object3 now. This means Object3 needs to be modified, adding a pair of signal/slot just to

Multi patterend varadic templates in C++

会有一股神秘感。 提交于 2019-12-24 07:18:18
问题 I don't think this is possible based on what I've read however I'm hoping someone here may know of some solution that would get this to work. I have a vector (maths) class for C++ template <typename T, size_t N> class vec; And want to create a varadic friend function apply to apply a function to these vectors element-wise i.e. template <typename F, typename ...Args> friend vec<typename std::result_of<pow(Args&&...)>::type, N> apply(F&& f, const vec<Args, N>&... args); which is valid (untested

Making sfinae works for functions with deduced return type?

六月ゝ 毕业季﹏ 提交于 2019-12-24 05:04:45
问题 Consider the following code: // -------------------------------------------------------------------------- // // Preprocessor #include <array> #include <vector> #include <utility> #include <iostream> #include <type_traits> // -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- // // Calls a function without arguments if it can be called template < class F, class... Args, class = decltype

Create a directory for every element of a path if it does not exist

时光总嘲笑我的痴心妄想 提交于 2019-12-24 04:01:50
问题 In C++, I want to create a directory from a path "path/that/consists/of/several/elements" . Also I want to create all parent directories of that directory in case they are not existing. How to do that with std C++? 回答1: std::experimental::filesystem/std::filesystem (C++14/C++17) provides create_directories(). It creates a directory for every path element if it does not already exist. For that it executes create_directory() for every such element. #include <experimental/filesystem> #include

Construction of an intializer_list<string> in a Lambda Capture

强颜欢笑 提交于 2019-12-24 02:04:48
问题 So I was cooking up an answer here and I needed to use C++14's identifier initializer within a lambda capture: const auto cmp = [ordering = { "dog", "cat", "mouse", "elephant" }](const string& lhs, const string& rhs) { return find(cbegin(ordering), cend(ordering), lhs) < find(cbegin(ordering), cend(ordering), rhs); }; And this works fine as long as ordering is an intializer_list<const char*> . But for some reason everything falls apart if I make it an intializer_list<string> : const auto cmp

Get the size of a member variable [duplicate]

独自空忆成欢 提交于 2019-12-24 01:13:22
问题 This question already has answers here : Does not evaluating the expression to which sizeof is applied make it legal to dereference a null or invalid pointer inside sizeof in C++? (3 answers) Is sizeof(*ptr) undefined behavior when pointing to invalid memory? (6 answers) Does the 'offsetof' macro from <stddef.h> invoke undefined behaviour? (6 answers) Why doesn't my program seg fault when I dereference a NULL pointer inside of malloc? (4 answers) Closed last year . There was a bug in g++-4.1

clang++ auto return type error for specialization of templated method in templated class?

橙三吉。 提交于 2019-12-24 01:13:01
问题 Trying to understand another question, I've simplified the example obtaining the following code. template <bool> struct foo { template <typename T> auto bar (int i) { return i; } }; template <> template <typename T> auto foo<true>::bar (int i) { return i; } int main() { return 0; } g++ 4.9.2 compile it without problem; clang++ 3.5 give the following error tmp_003-14,gcc,clang.cpp:12:20: error: out-of-line definition of 'bar' does not match any declaration in 'foo<true>' auto foo<true>::bar

Getting the biggest type from a variadic type list

ぃ、小莉子 提交于 2019-12-24 00:38:14
问题 I'm trying to get the biggest type from a variadic template type list. I'm getting unexpected results: // Bigger between two types template<typename T1, typename T2> using Bigger = std::conditional_t<sizeof(T1) >= sizeof(T2), T1, T2>; // Recursion helper template<typename...> struct BiggestHelper; // 2 or more types template<typename T1, typename T2, typename... TArgs> struct BiggestHelper<T1, T2, TArgs...> { using Type = Bigger<T1, BiggestHelper<T2, TArgs...>>; }; // Exactly 2 types template

The C++ detection idiom is not working as expected in Visual Studio 2015 Update 2 CTP

爱⌒轻易说出口 提交于 2019-12-24 00:14:38
问题 I'm playing with the proposal of standard library support for the C++ detection idiom and compiled the following code with the Microsoft C/C++ Optimizing Compiler Version 19.00.23725 for x64 : #include <iostream> template<class...> using void_t = void; template<class, template<class> class, class = void_t<>> struct detect : std::false_type { }; template<class T, template<class> class Operation> struct detect<T, Operation, void_t<Operation<T>>> : std::true_type { }; template<class T> using bar

Template compilation error: 'X' does not refer to a value

风格不统一 提交于 2019-12-23 23:19:06
问题 I am getting the following error: 'ComponentManager' does not refer to a value when compiling a subclass which inherits from this parent class: template<typename ComponentManager> class component_collection { protected: int n_components; int n_versions; int first_blank; int last_used; std::vector<std::deque<shared_ptr<entity<ComponentManager>>>> entity_pointers; public: component_collection(int n_c, int n_v) : n_components(n_c), n_versions(n_v), first_blank(0), last_used(0), entity_pointers(n