c++17

Compilation errors for C++17 <filesystem> on MinGW

本秂侑毒 提交于 2020-01-21 19:16:28
问题 I want to play around with the new filesystem library that's now apart of the C++17 standard, however I can't get things to compile. Things I've already tried: Updating MinGW to 8.2.0 Compiling with g++ -std=c++17 test.cpp -o test Adding -lstdc++fs to the compilation (this does not work, I get the error c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lstdc++fs ) Using <filesystem> as well as <experimental\filesystem> Here is my simple test code just to try

Declaring a member function with a typedef coming from a metafunction

ぐ巨炮叔叔 提交于 2020-01-21 04:45:18
问题 Consider the following code: template <class> struct Foo_s { using type = void(); }; template <class> using Foo_u = void(); template <class T> struct Bar { Foo_u<void> foo1; // OK typename Foo_s<void>::type foo2; // OK Foo_u<T> foo3; // OK typename Foo_s<T>::type foo4; // Boom. }; template struct Bar<void>; The declaration of foo4 fails on GCC 7.2, Clang 5.0.0 and MSVC 19.10.25017. GCC: <source>: In instantiation of 'struct Bar<void>': 18 : <source>:18:17: required from here 15 : <source>:15

C++17 fold expression syntax?

只谈情不闲聊 提交于 2020-01-21 04:38:06
问题 I am trying to use compact fold expression without success. For instance here is a working C++17 code template <bool... B> struct Fold_And : std::integral_constant<bool, (B && ...)> { }; template <bool... B> constexpr auto Fold_And_v = Fold_And<B...>::value; template <typename V, typename... Vs> std::enable_if_t< Fold_And_v<std::is_floating_point_v<V>, std::is_floating_point_v<Vs>...> > foo(const V& v, const Vs&...) { } I want to translate it into a more compact form (not using the

Can I extend variant in C++?

风流意气都作罢 提交于 2020-01-21 04:34:04
问题 I'm not sure that this is possible, but say I have: using my_variant = std::variant<Class1, Class2, Class3>; Now at some point, I create a Class4 and would like to extend my_variant2 to include all of my_variant along with Class4 (in a general way, i.e. not just using another using... ) so that I can do something like create an array std::array<my_variant2, n> . Is this something that can be done? 回答1: godbolted #include <variant> template <typename T, typename... Args> struct concatenator;

Why void_t doesnt work in SFINAE but enable_if does

徘徊边缘 提交于 2020-01-21 02:38:45
问题 I was trying to understand how SFINAE works and I was experimenting with this code #include <type_traits> struct One { using x = int; }; struct Two { using y = int; }; template <typename T, std::void_t<typename T::x>* = nullptr> void func() {} template <typename T, std::void_t<typename T::y>* = nullptr> void func() {} /*template <typename T, std::enable_if_t<std::is_same_v<typename T::x, typename T::x>>* = nullptr> void func() {} template <typename T, std::enable_if_t<std::is_same_v<typename

How the new range-based for loop in C++17 helps Ranges TS?

陌路散爱 提交于 2020-01-19 04:36:25
问题 The committee changed the range-based for loop from: C++11: { auto && __range = range_expression ; for (auto __begin = begin_expr, __end = end_expr; __begin != __end; ++__begin) { range_declaration = *__begin; loop_statement } } to C++17 : { auto && __range = range_expression ; auto __begin = begin_expr ; auto __end = end_expr ; for ( ; __begin != __end; ++__begin) { range_declaration = *__begin; loop_statement } } And people said that this will make implementing Ranges TS easier. Can you

Cannot move std::any

旧街凉风 提交于 2020-01-16 18:02:06
问题 The following code using vptr = std::vector<std::unique_ptr<int>>; auto m = std::unordered_map<int, std::any>{}; m.try_emplace(0, move(vptr{})); Fails to compile, complaining about using of deleted copy constructor of unique_ptr . After replacing std::any with vptr in template argument this code compiles, so the issue is clearly with any How can I force std::any to be moved instead of copied? 回答1: The problem is not moving std::any, it's that std::any itself does not support move-only types

Cannot move std::any

坚强是说给别人听的谎言 提交于 2020-01-16 18:01:09
问题 The following code using vptr = std::vector<std::unique_ptr<int>>; auto m = std::unordered_map<int, std::any>{}; m.try_emplace(0, move(vptr{})); Fails to compile, complaining about using of deleted copy constructor of unique_ptr . After replacing std::any with vptr in template argument this code compiles, so the issue is clearly with any How can I force std::any to be moved instead of copied? 回答1: The problem is not moving std::any, it's that std::any itself does not support move-only types

How to create a c++ enum from a C style #define and struct (or what's the right way to do this)?

心已入冬 提交于 2020-01-16 08:41:28
问题 I'm working with a C library (Raylib) that uses the following for color representation: #define RED { 230, 41, 55, 255 } // Color type, RGBA (32bit) typedef struct Color { unsigned char r; unsigned char g; unsigned char b; unsigned char a; } Color; I want to define an enum of all the Color objects that I will use in my palette in my C++ code. But enum class only allows integral kinds of values. What's the best way to have a fixed static set of values which are non-integral? One approach I

Passing variadic parameters in an already template-variadic function

我与影子孤独终老i 提交于 2020-01-16 06:55:51
问题 The title is bad but I couldn't come up with anything better. Feel free to change it. Here's a template multidimensional array class that I'm currently working on. I'm trying to optimise it as much as I can: #include <array> template <typename T, std::size_t... Dimensions> class multidimensional_array { public: using value_type = T; using size_type = std::size_t; private: template<typename = void> static constexpr size_type multiply(void) { return 1u; } template<std::size_t First, std::size_t