c++17

constexpr struct member initialisation

一曲冷凌霜 提交于 2020-06-12 04:33:26
问题 This code compiles: struct Info { constexpr Info(bool val) : counted(false), value(unsigned(val)) {} constexpr Info(unsigned val) : counted(true), value(val) {} bool counted; unsigned value; }; constexpr const auto data = std::array{ Info{true}, Info{42u} }; struct Foo { constexpr static inline const auto data = std::array{ Info{true}, Info{42u} }; }; This code does not: struct Foo { struct Info { constexpr Info(bool val) : counted(false), value(unsigned(val)) {} constexpr Info(unsigned val)

C++17 filesystem using nuwen MinGW on Windows 10

萝らか妹 提交于 2020-06-12 02:52:53
问题 I wanted to try out the new filesystem library in C++17, so tried copying the std::filesystem::current_path example from cppreference.com and compiling it using the latest version (16.0) of the MinGW distribution from nuwen.net on my Windows 10 x64 machine. This includes gcc v8.1 which should support the filesystem library according to cppreference.com compiler support page. Here is the code that I am trying to compile: #include <iostream> #include <filesystem> namespace fs = std::filesystem;

C++17 filesystem using nuwen MinGW on Windows 10

为君一笑 提交于 2020-06-12 02:49:27
问题 I wanted to try out the new filesystem library in C++17, so tried copying the std::filesystem::current_path example from cppreference.com and compiling it using the latest version (16.0) of the MinGW distribution from nuwen.net on my Windows 10 x64 machine. This includes gcc v8.1 which should support the filesystem library according to cppreference.com compiler support page. Here is the code that I am trying to compile: #include <iostream> #include <filesystem> namespace fs = std::filesystem;

How can I intentionally discard a [[nodiscard]] return value?

ぐ巨炮叔叔 提交于 2020-06-11 16:18:06
问题 Say I have [[nodiscard]] int foo () { return 0; } int main () { foo (); } then error: ignoring return value of ‘int foo()’, declared with attribute nodiscard [-Werror=unused-result] but if int x = foo (); then error: unused variable ‘x’ [-Werror=unused-variable] Is there a clean way of telling the compiler "I want to discard this [[nodiscard]] value"? 回答1: The WG14 nodiscard proposal discusses the rationale for allowing the diagnostic to be silenced by casting to void. It says casting to void

How can I intentionally discard a [[nodiscard]] return value?

空扰寡人 提交于 2020-06-11 16:17:57
问题 Say I have [[nodiscard]] int foo () { return 0; } int main () { foo (); } then error: ignoring return value of ‘int foo()’, declared with attribute nodiscard [-Werror=unused-result] but if int x = foo (); then error: unused variable ‘x’ [-Werror=unused-variable] Is there a clean way of telling the compiler "I want to discard this [[nodiscard]] value"? 回答1: The WG14 nodiscard proposal discusses the rationale for allowing the diagnostic to be silenced by casting to void. It says casting to void

Is there a way to disallow “experimental” C++17 in CMake configuration?

自古美人都是妖i 提交于 2020-06-11 08:02:28
问题 I have set the following in my CMakeLists.txt: set (CMAKE_CXX_STANDARD 17) set (CMAKE_CXX_STANDARD_REQUIRED ON) set (CMAKE_CXX_EXTENSIONS OFF) However, CMake still allows g++ 6, even though it doesn't fully support c++17 (it has a c++1z standard, but not a c++17 standard). Is there a way to tell CMake to only allow compilers that fully support the standard and not just pieces of it? FWIW, I also tried setting cxx_relaxed_constexpr, which I think should have been the relevant language feature,

Test if std::common_type exists

拟墨画扇 提交于 2020-06-11 03:45:30
问题 I want to write a helper template that checks if a template parameter pack has a common type, i.e., if applying std::common_type to the pack defines a type. Using std::void_t with SFINAE I came up with the following definition: template<typename... Types, typename Enable = void> struct has_common_type : std::false_type { }; template<typename... Types> struct has_common_type<Types..., std::void_t<std::common_type<Types...>::type>> : std::true_type { }; This however does not work, because the

Test if std::common_type exists

耗尽温柔 提交于 2020-06-11 03:41:52
问题 I want to write a helper template that checks if a template parameter pack has a common type, i.e., if applying std::common_type to the pack defines a type. Using std::void_t with SFINAE I came up with the following definition: template<typename... Types, typename Enable = void> struct has_common_type : std::false_type { }; template<typename... Types> struct has_common_type<Types..., std::void_t<std::common_type<Types...>::type>> : std::true_type { }; This however does not work, because the

Test if std::common_type exists

末鹿安然 提交于 2020-06-11 03:41:34
问题 I want to write a helper template that checks if a template parameter pack has a common type, i.e., if applying std::common_type to the pack defines a type. Using std::void_t with SFINAE I came up with the following definition: template<typename... Types, typename Enable = void> struct has_common_type : std::false_type { }; template<typename... Types> struct has_common_type<Types..., std::void_t<std::common_type<Types...>::type>> : std::true_type { }; This however does not work, because the

What does “there is no smaller array object that satisfies these constraints” mean?

谁都会走 提交于 2020-06-10 08:43:42
问题 The draft n4659 for C++17 describes the general principes of the language in chapter 4. In chapter 4.5, The C++ object model [intro.object], I cannot understand the meaning of one sentence (emphasize mine) 3 If a complete object is created (8.3.4) in storage associated with another object e of type “array of N unsigned char” or of type “array of N std::byte” (21.2.1), that array provides storage for the created object if: (3.1) — the lifetime of e has begun and not ended, and (3.2) — the