c++14

Compiler-enforced semantic types

∥☆過路亽.° 提交于 2020-12-31 06:29:48
问题 Say I have a class representing automata, whose states are numbered ( using state_t = unsigned ) and whose transitons are also numbered ( using transition_t = unsigned ). Of course at some point I end up messing some calls because transition_t and state_t are the same type, so the compiler does not enforce the (semantic) type safety. That's easy to workaround by using a small class templated by a tag ( struct transition_tag {}; struct state_tag {}; ), so now transition_t and state_t are

Enums support for inheritance

笑着哭i 提交于 2020-12-31 06:09:42
问题 I frequently come across a situation where we create a class that acts on some enumeration, but later we derive and we want to add more values to the enumeration without changing the base class. I see this question from 2009: Base enum class inheritance However, I know there were a number of changes to enum in C++11, 14, 17. Do any of those changes allow for extension of enums from base class to derived? class Base { enum State {STATE_1, STATE_2, STATE_3}; }; class Derived : public Base {

Enums support for inheritance

跟風遠走 提交于 2020-12-31 06:09:34
问题 I frequently come across a situation where we create a class that acts on some enumeration, but later we derive and we want to add more values to the enumeration without changing the base class. I see this question from 2009: Base enum class inheritance However, I know there were a number of changes to enum in C++11, 14, 17. Do any of those changes allow for extension of enums from base class to derived? class Base { enum State {STATE_1, STATE_2, STATE_3}; }; class Derived : public Base {

Enums support for inheritance

痞子三分冷 提交于 2020-12-31 06:05:27
问题 I frequently come across a situation where we create a class that acts on some enumeration, but later we derive and we want to add more values to the enumeration without changing the base class. I see this question from 2009: Base enum class inheritance However, I know there were a number of changes to enum in C++11, 14, 17. Do any of those changes allow for extension of enums from base class to derived? class Base { enum State {STATE_1, STATE_2, STATE_3}; }; class Derived : public Base {

Enums support for inheritance

安稳与你 提交于 2020-12-31 06:04:11
问题 I frequently come across a situation where we create a class that acts on some enumeration, but later we derive and we want to add more values to the enumeration without changing the base class. I see this question from 2009: Base enum class inheritance However, I know there were a number of changes to enum in C++11, 14, 17. Do any of those changes allow for extension of enums from base class to derived? class Base { enum State {STATE_1, STATE_2, STATE_3}; }; class Derived : public Base {

C++ Transform a std::tuple<A, A, A…> to a std::vector or std::deque

风流意气都作罢 提交于 2020-12-28 07:51:23
问题 In the simple parser library I am writing, the results of multiple parsers is combined using std::tuple_cat . But when applying a parser that returns the same result multiple times, it becomes important to transform this tuple into a container like a vector or a deque. How can this be done? How can any tuple of the kind std::tuple<A> , std::tuple<A, A> , std::tuple<A, A, A> etc be converted into a std::vector<A> ? I think this might be possible using typename ...As and sizeof ...(As) , but I

C++ Transform a std::tuple<A, A, A…> to a std::vector or std::deque

一世执手 提交于 2020-12-28 07:49:44
问题 In the simple parser library I am writing, the results of multiple parsers is combined using std::tuple_cat . But when applying a parser that returns the same result multiple times, it becomes important to transform this tuple into a container like a vector or a deque. How can this be done? How can any tuple of the kind std::tuple<A> , std::tuple<A, A> , std::tuple<A, A, A> etc be converted into a std::vector<A> ? I think this might be possible using typename ...As and sizeof ...(As) , but I

C++ Transform a std::tuple<A, A, A…> to a std::vector or std::deque

依然范特西╮ 提交于 2020-12-28 07:49:05
问题 In the simple parser library I am writing, the results of multiple parsers is combined using std::tuple_cat . But when applying a parser that returns the same result multiple times, it becomes important to transform this tuple into a container like a vector or a deque. How can this be done? How can any tuple of the kind std::tuple<A> , std::tuple<A, A> , std::tuple<A, A, A> etc be converted into a std::vector<A> ? I think this might be possible using typename ...As and sizeof ...(As) , but I

How to `std::bind()` a standard library algorithm?

好久不见. 提交于 2020-12-24 08:54:01
问题 The short version of my question is this: How can I use something like std::bind() with a standard library algorithm? Since the short version is a bit devoid of details, here is a bit of an explanation: Assume I have the algorithms std::transform() and now I want to implement std::copy() (yes, I realize that there is std::copy() in the standard C++ library). Since I'm hideously lazy, I clearly want to use the existing implementation of std::transform() . I could, of course, do this: struct

How to `std::bind()` a standard library algorithm?

六月ゝ 毕业季﹏ 提交于 2020-12-24 08:53:25
问题 The short version of my question is this: How can I use something like std::bind() with a standard library algorithm? Since the short version is a bit devoid of details, here is a bit of an explanation: Assume I have the algorithms std::transform() and now I want to implement std::copy() (yes, I realize that there is std::copy() in the standard C++ library). Since I'm hideously lazy, I clearly want to use the existing implementation of std::transform() . I could, of course, do this: struct