c++17

C++ Self registering factory in library: No types registered in application

回眸只為那壹抹淺笑 提交于 2020-01-23 17:27:49
问题 I modified the factory pattern with self registering types from this blog post for my own needs. Instead of strings I use UUIDs (using boost.uuid ) to register & build my node sub-classes. The factory and corresponding node and node_* subclasses are part of a library. I link against that library (static library) in my client application and then want to use the library's factory::build() function to build objects based on the known UUIDs. The problem I am facing is that everything is working

c++ reversed integer sequence implementation

ぐ巨炮叔叔 提交于 2020-01-23 12:07:54
问题 Who knows how to implement C++ std::make_index_sequence reverse version. To get - make_index_sequence_reverse<int, 5> = <4,3,2,1,0> . Thank you! 回答1: IMHO, there is no reason for a index_sequence_reverse : std::index_sequence support sequences of indexes and are order neutral (or even without order). If you can use std::make_index_sequence , for a makeIndexSequenceReverse you can make something as follows #include <utility> #include <type_traits> template <std::size_t ... Is> constexpr auto

c++ reversed integer sequence implementation

点点圈 提交于 2020-01-23 12:07:40
问题 Who knows how to implement C++ std::make_index_sequence reverse version. To get - make_index_sequence_reverse<int, 5> = <4,3,2,1,0> . Thank you! 回答1: IMHO, there is no reason for a index_sequence_reverse : std::index_sequence support sequences of indexes and are order neutral (or even without order). If you can use std::make_index_sequence , for a makeIndexSequenceReverse you can make something as follows #include <utility> #include <type_traits> template <std::size_t ... Is> constexpr auto

Call a functor with a specific function from an overload set

喜欢而已 提交于 2020-01-23 09:10:40
问题 Context In mathematics-related context, I'd like to define functors working on <cmath> functions. For the purpose of this question, we will be using std::invoke as our functor. This is ill-formed (live demo): std::invoke(std::sin, 0.0); (g++-8.1) error: no matching function for call to 'invoke(<unresolved overloaded function type>, double)' Indeed, std::sin is an overload set and the compiler lacks the type information to choose one of those functions. Question How could I name a specific

Call a functor with a specific function from an overload set

﹥>﹥吖頭↗ 提交于 2020-01-23 09:09:07
问题 Context In mathematics-related context, I'd like to define functors working on <cmath> functions. For the purpose of this question, we will be using std::invoke as our functor. This is ill-formed (live demo): std::invoke(std::sin, 0.0); (g++-8.1) error: no matching function for call to 'invoke(<unresolved overloaded function type>, double)' Indeed, std::sin is an overload set and the compiler lacks the type information to choose one of those functions. Question How could I name a specific

How to determine whether to use <filesystem> or <experimental/filesystem>?

微笑、不失礼 提交于 2020-01-22 19:43:24
问题 Is there a way to determine whether I can use the standard <filesystem> (which is available on all modern C++ compilers that support C++17) or <experimental/filesystem> which is used by older compilers. (For example g++ 6.3, which is the current standard version on Debian Stretch) Knowing which one to use is imporant because the first uses std::filesystem::xxx and the latter std::experimental::filesystem::xxx . 回答1: I typically create a header filesystem.hpp with the following content: // We

How to determine whether to use <filesystem> or <experimental/filesystem>?

醉酒当歌 提交于 2020-01-22 19:43:10
问题 Is there a way to determine whether I can use the standard <filesystem> (which is available on all modern C++ compilers that support C++17) or <experimental/filesystem> which is used by older compilers. (For example g++ 6.3, which is the current standard version on Debian Stretch) Knowing which one to use is imporant because the first uses std::filesystem::xxx and the latter std::experimental::filesystem::xxx . 回答1: I typically create a header filesystem.hpp with the following content: // We

Construct an empty object without the default constructor

女生的网名这么多〃 提交于 2020-01-22 16:25:39
问题 Suppose I have a type F . I know that F is empty, but F has no default constructor, so I can't use F() to construct it. Is there a way to obtain a valid object of type F anyway? I seem to recall a mention that there was such a way with arcane usage of unions. Ideally, it would be constexpr friendly. This can be useful because captureless lambdas only gained a default constructor in C++20. In C++17, if I want to "pass a lambda to a template" and call that lambda without having an instance of

Construct an empty object without the default constructor

℡╲_俬逩灬. 提交于 2020-01-22 16:25:22
问题 Suppose I have a type F . I know that F is empty, but F has no default constructor, so I can't use F() to construct it. Is there a way to obtain a valid object of type F anyway? I seem to recall a mention that there was such a way with arcane usage of unions. Ideally, it would be constexpr friendly. This can be useful because captureless lambdas only gained a default constructor in C++20. In C++17, if I want to "pass a lambda to a template" and call that lambda without having an instance of

T declval() instead of T && declval() for common_type

半世苍凉 提交于 2020-01-22 15:33:05
问题 Isn't it better to use std::declval declared in form: template< class T > T declval(); // (1) then current one: template< class T > T && declval(); // (2) for std::common_type (possibly with different name only for this current purpose)? Behaviour of common_type using (1) is closer to the behaviour of the ternary operator (but not using std::decay_t ) than the behaviour when using (2) : template< typename T > T declval(); template <class ...T> struct common_type; template< class... T > using