FAQ Database Discussion Community


Rationale behind std::bool_constant

c++,c++1z
I'm wondering, what is the rationale behind introducing std::bool_constant and its subsequent use for std::true_type and std::false_type (as well as the comparison structs defined in header <ratio>, cf. N4389) in C++17? Thus far I've only been able to locate the papers containing the wording: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4334.html http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4389.html While both paper refer...

experimental::optional nullopt_t constructor

c++,optional,c++1z
Here is described the nullopt_t and nullopt for the optional object proposed for c++: struct nullopt_t{see below}; constexpr nullopt_t nullopt(unspecified); [...] Type nullopt_t shall not have a default constructor. It shall be a literal type. Constant nullopt shall be initialized with an argument of literal type. The reason for this...

Get types of function parameters

c++,templates,variadic-templates,c++14,c++1z
Is there a standard way to get the types of a function's arguments and pass around these types as a template parameter pack? I know that this is possible in C++ because it has been done before. I was hoping that with C++14 or the upcoming C++1z, there would be...

How do I build gcc with C++ concepts (“concepts lite”) support?

c++,g++,generic-programming,c++-concepts,c++1z
The C++ standards committee is working on a TS (Technical Specification) for Concepts extension: "Programming Languages - C++ Extensions for Concepts". N4377 is the latest version of this document. For inclusion into the C++ standard features are asked to be implemented, ideally for a publicly accessible system. I'm aware of...

C++1z handling of a == test with std::initializer_list with and w/o const in an auto function

c++,auto,c++14,initializer-list,c++1z
c_NEXT is defined in class AskBase: struct Status { static auto constexpr c_ROOT {-999}; static auto constexpr c_PREVIOUS {-1}; static auto constexpr c_NEXT {1}; static auto constexpr c_EOF {999}; }; Later c_NEXT is used in template<typename Container> class AskUI auto run(){ auto status = AskBase::Status::c_NEXT; for (typename Container::iterator ii=m_asks.begin(); ii!=m_asks.end();...

Choose between template function and auto type deduction

c++,templates,auto,c++14,c++1z
I have a generic question about template functions versus auto type deduction for functions. For years, we have have been able to write template function : template <class T> T add(T a,T b){ return a+b; } There is a TS for using auto for function's parameters deduction auto add(auto a,auto...

Will there be standardization of scope guard/scope exit idioms?

c++,c++14,c++1z,scopeguard
Running a lambda on scope exit seems like such a basic thing, I would expect it to be standardized. Things like unique_ptr are better, when they apply, but I find there is an endless supply of "one-off" destructors are needed, especially when leveraging C-style libraries. Does anyone know if this...

Why doesn't a left fold expression invert the output of a right fold expression?

c++,templates,c++1z,fold-expression
I'm taking a look at C++17 fold expressions and I'm wondering why does the following program outputs 4 5 6 4 5 6 for both of the for_each calls template<typename F, typename... T> void for_each1(F fun, T&&... args) { (fun (std::forward<T>(args)), ...); } template<typename F, typename... T> void for_each2(F fun,...

Lambda as default argument fails

c++,c++1z
I get an error with the latest versions of clang and gcc with this code: int main() { auto lambda = [] (auto = [] {}) {}; lambda(); } Clang gives the error: prog.cc: In function 'int main()': prog.cc:3:12: error: no match for call to '(main()::<lambda(auto:1)>) ()' lambda(); ^ prog.cc:2:35:...

Is the value of expression f() > g(), when f & g modify same global variable undefined or unspecified?

c++,c++11,c++14,c++1z
UPDATE: As marked by user ecatmur, it's a duplicate of In C99, is f()+g() undefined or merely unspecified? (although the questions asks about C99, but answer is unchanged for C++). And the answer is: unspecified (for both cases). Consider following C++14 code fragment: int i = 0; int x() {...

What's wrong with register keyword in C++? [duplicate]

c++,cpu-registers,c++1z,storage-class-specifier
This question already has an answer here: Register keyword C++ 11 3 answers I was reading this and it says that the register keyword will most probably be removed from the next C++ standard. It also says that register was deprecated in 2011. So, what's wrong with register storage...

Writing a modern function interface to “produce a populated container”

c++,c++11,c++14,c++1z
When I cut my teeth on C++03, I learned several approaches to writing a "give me the collection of things" function. But each has some setbacks. template< typename Container > void make_collection( std::insert_iterator<Container> ); This must be implemented in a header file The interface doesn't communicate that an empty container...

clang 3.6 fold expression left/right

c++,clang,clang++,c++1z
I'm trying the fold expression with clang 3.6 '--std=c++1z', but something I don't quite get. The function that I'm testing is: auto minus = [](auto... args) { return (args - ...); }; ... std::cout << minus(10, 3, 2) << std::endl; according to n4191, I'm expecting it expands as a left...

Is there a proposal to extend the C++ language so as to obviate pimpl?

c++,pimpl-idiom,c++1z,language-extension
Sometimes, you want to provide a class declaration, which is not merely an opaque forward declaration but has the public functionality exposed - yet you don't want to commit to your private, or implementation-specific, fields and methods. One solution for this is the pimpl idiom - using a pointer to...

Understanding Alias Templates

c++,templates,alias,enable-if,c++1z
I asked a question that has several references to the code: template <typename...> using void_t = void; I believe I have a generally misunderstand alias templates: Why wouldn't you just evaluate whatever template parameter you're passing into an alias template in an enable_if_t or conditional_t statement? Is the code above...

C++14 using alias for is_same::value

c++,templates,helper,c++14,c++1z
This question uses is_same<uint64_t, decltype(val)>::value. I expected there to be a C++14 using alias: is_same_v similar to the helper types: conditional_t, enable_if_t, and tuple_element_t which I use in my answer. Because the only thing I ever use any of those functions for is to get the type. So the *_t...

Template class with invalid member functions

c++,templates,c++1z
Is it legal in C++ to have instantiate class templates with classes that do not work with some of its member functions? For example: class A { public: void f() { } }; class B { }; template<typename T> class Wrapper { private: T t_; public: void call_f() { t_.f();...