c++14

Why doesn't N3421 provide the noexcept qualifier?

て烟熏妆下的殇ゞ 提交于 2019-12-30 09:52:23
问题 In N3421 - Making Operator Functors greater<>, the new specialization for the std function objects is: template <> struct plus<void> { template <class T, class U> auto operator()(T&& t, U&& u) const -> decltype(std::forward<T>(t) + std::forward<U>(u)); }; instead of template <> struct plus<void> { template <class T, class U> auto operator()(T&& t, U&& u) const noexcept(noexcept(decltype(std::forward<T>(t) + std::forward<U>(u)) (std::move(std::forward<T>(t) + std::forward<U>(u))))) -> decltype

Is unique_ptr<Derived> to unique_ptr<Base> up-casting automatic?

流过昼夜 提交于 2019-12-30 08:15:41
问题 I know it is possible that a derived class unique_ptr can take place where base class unique_ptr is required for polymorphic types. For example, while returning from function unique_ptr<Base> someFunction() { return make_unique<Derived>(new Derived()); } or passing to function as argument. // Function taking unique pointer void someOtherFunction(unique_ptr<Base>&& ptr) // Code calling this function someOtherFunction(std::move(ptrToDerived)); My question is: Is this upcasting always automatic?

Is a defaulted constructor/assignment noexcept/constexpr by default?

南笙酒味 提交于 2019-12-30 08:04:30
问题 So, my question is simple: Is there any point in specifying a defaulted class constructor as noexcept or constexpr (or any other thing you could thing of)? struct foo { foo() = default; // vs constexpr foo() noexcept = default; // same thing would apply for copy/move ctors and assignment operators }; Would the two behave the same way? Does it depend on whether the class is POD? For example with the above example both would behave the same way, while if for example I had a private member std:

How to construct a tuple from an array

我是研究僧i 提交于 2019-12-30 03:30:07
问题 I am designing a C++ library that reads a CSV file of reported data from some experiment and does some aggregation and outputs a pgfplots code. I want to make the library as generic and easy to use as possible. I also want to isolate it from the data types that are represented in the CSV file and leave the option to user to parse each column as she desires. I also want to avoid Boost Spirit Qi or other heavy duty parser. The simple solution I have is for the user to create a type for each

Lvalues which do not designate objects in C++14

瘦欲@ 提交于 2019-12-30 03:25:13
问题 I'm using N3936 as a reference here (please correct this question if any of the C++14 text differs). Under 3.10 Lvalues and rvalues we have: Every expression belongs to exactly one of the fundamental classifications in this taxonomy: lvalue, xvalue, or prvalue. However the definition of lvalue reads: An lvalue [...] designates a function or an object. In 4.1 Lvalue-to-rvalue conversion the text appears: [...] In all other cases, the result of the conversion is determined according to the

Get function return type in template

霸气de小男生 提交于 2019-12-30 02:24:07
问题 How can I get return type for any function passed to template? I don't know how to convert between template<typename T> and template<typename Result, typename Args...> : template<typename T> void print_name(T f) { static_assert(internal::is_function_pointer<T>::value || std::is_member_function_pointer<T>::value, "T must be function or member function pointer."); typename decltype(f(...)) Result; // ??? typename std::result_of<T>()::type Result; // ??? printf("%s\n", typeid(Result).name()); }

Why is initialization of a constant dependent type in a template parameter list disallowed by the standard?

。_饼干妹妹 提交于 2019-12-30 00:49:05
问题 In the answer to this post "(Partially) specializing a non-type template parameter of dependent type", it states: The type of a template parameter corresponding to a specialized non-type argument shall not be dependent on a parameter of the specialization. [ Example: template <class T, T t> struct C {}; template <class T> struct C<T, 1>; // error template< int X, int (*array_ptr)[X] > class A {}; int array[5]; template< int X > class A<X,&array> { }; // error —end example ] My question is why

Move constructor is required even if it is not used. Why?

本小妞迷上赌 提交于 2019-12-29 08:50:51
问题 Why?! Why C++ requires the class to be movable even if it's not used! For example: #include <iostream> using namespace std; struct A { const int idx; // It could not be compileld if I comment out the next line and uncomment // the line after the next but the moving constructor is NOT called anyway! A(A&& a) : idx(a.idx) { cout<<"Moving constructor with idx="<<idx<<endl; } // A(A&& a) = delete; A(const int i) : idx(i) { cout<<"Constructor with idx="<<i<<endl; } ~A() { cout<<"Destructor with

Initializing a static constexpr data member of the base class by using a static constexpr data member of the derived class

浪尽此生 提交于 2019-12-29 06:43:14
问题 Consider the following code: template<typename T> struct S { static constexpr int bar = T::foo; }; struct U: S<U> { static constexpr int foo = 42; }; int main() { } GCC v6.1 compiles it, clang 3.8 rejects it with the error: 2 : error: no member named 'foo' in 'U' struct S { static constexpr int bar = T::foo; }; Which compiler is right? Could it be due to the fact that U is not a complete type at the point where we try to use it within S ? In this case, it should be considered a bug of GCC,

What are the 6 dots in template parameter packs? [duplicate]

 ̄綄美尐妖づ 提交于 2019-12-29 03:15:06
问题 This question already has answers here : What is the meaning of “… …” token? i.e. double ellipsis operator on parameter pack (2 answers) Closed 5 years ago . While looking at this question I found myself in the cpp reference site where I noticed a strange and new to me syntax : template<class Ret, class... Args> struct is_function<Ret(Args......)volatile &&> : std::true_type {}; Yep, 6 dots ! Initially I thought this was a typo, but after checking the libstdc++ source again there it was eg at