c++17

Clang and GCC disagree in auto specifier for non-type template parameter in a casting C++17

吃可爱长大的小学妹 提交于 2020-01-01 04:04:01
问题 I basically have a class that depends on a non-type template parameter. I defined a casting so an object of non-type template parameter N can convert to another of M . I have a minimal example that can reproduce the situation: template<auto Integral> class Test{ public: typedef decltype(Integral) value_type; static constexpr value_type N = Integral; constexpr Test (const value_type& x = 0); template<auto Integral2> constexpr explicit operator Test<Integral2>() const; private: value_type n; };

Is there sense in using const std::string& arguments in C++17?

青春壹個敷衍的年華 提交于 2020-01-01 03:53:11
问题 By getting string_view in C++17 we got cheap method of passing both std::string and char* to functions that do not take ownership of the string and avoid making temporary copies. By using std::string passed by value and std::move we get explicit and fast passing of string ownership for both r-value and l-value references. My question is: is there any benefit in using const std::string& as any function parameter in new C++ standard? 回答1: Yes. The problem with std::string_view is that it doesn

Managing trivial types

て烟熏妆下的殇ゞ 提交于 2020-01-01 02:09:32
问题 I have found the intricacies of trivial types in C++ non-trivial to understand and hope someone can enlighten me on the following. Given type T , storage for T allocated using ::operator new(std::size_t) or ::operator new[](std::size_t) or std::aligned_storage , and a void * p pointing to a location in that storage suitably aligned for T so that it may be constructed at p : If std::is_trivially_default_constructible<T>::value holds, is the code invoking undefined behavior when code skips

Redefinitions of constexpr static data members are allowed now? (but not inline const)?

六月ゝ 毕业季﹏ 提交于 2019-12-31 20:18:21
问题 The following fails to compile under both gcc and clang in c++14, but succeeds with c++1z: struct Cls { static constexpr int N = 0; }; constexpr int Cls::N; constexpr int Cls::N; The C++14 error is predictable: redefinition of ‘constexpr const int Cls::N’ What changed to make this legal? I found: n4659 10.1.5 [dcl.constexpr] A function or static data member declared with the constexpr specifier is implicitly an inline function or variable So I thought it might have to do with inline variables

Redefinitions of constexpr static data members are allowed now? (but not inline const)?

女生的网名这么多〃 提交于 2019-12-31 20:18:09
问题 The following fails to compile under both gcc and clang in c++14, but succeeds with c++1z: struct Cls { static constexpr int N = 0; }; constexpr int Cls::N; constexpr int Cls::N; The C++14 error is predictable: redefinition of ‘constexpr const int Cls::N’ What changed to make this legal? I found: n4659 10.1.5 [dcl.constexpr] A function or static data member declared with the constexpr specifier is implicitly an inline function or variable So I thought it might have to do with inline variables

How to make `short-circuit evaluation` also available in `fold expressions`?

我是研究僧i 提交于 2019-12-31 16:52:16
问题 #include <type_traits> #define FORWARD(arg)\ std::forward<decltype(arg)>(arg) template<typename... Args> constexpr bool AndL(Args&&... args) { return (... && FORWARD(args)); } template<typename... Args> constexpr bool AndR(Args&&... args) { return (FORWARD(args) && ...); } int main() { bool* pb = nullptr; false && (*pb = true); // ok at runtime. AndL(false, (*pb = true)); // error at runtime! AndR(false, (*pb = true)); // error at runtime! } The traditional && operator supports short-circuit

How to make `short-circuit evaluation` also available in `fold expressions`?

半城伤御伤魂 提交于 2019-12-31 16:51:37
问题 #include <type_traits> #define FORWARD(arg)\ std::forward<decltype(arg)>(arg) template<typename... Args> constexpr bool AndL(Args&&... args) { return (... && FORWARD(args)); } template<typename... Args> constexpr bool AndR(Args&&... args) { return (FORWARD(args) && ...); } int main() { bool* pb = nullptr; false && (*pb = true); // ok at runtime. AndL(false, (*pb = true)); // error at runtime! AndR(false, (*pb = true)); // error at runtime! } The traditional && operator supports short-circuit

Calling non-static member function outside of object's lifetime in C++17

谁说胖子不能爱 提交于 2019-12-31 11:24:04
问题 Does the following program have undefined behavior in C++17 and later? struct A { void f(int) { /* Assume there is no access to *this here */ } }; int main() { auto a = new A; a->f((a->~A(), 0)); } C++17 guarantees that a->f is evaluated to the member function of the A object before the call's argument is evaluated. Therefore the indirection from -> is well-defined. But before the function call is entered, the argument is evaluated and ends the lifetime of the A object (see however the edits

Calling non-static member function outside of object's lifetime in C++17

早过忘川 提交于 2019-12-31 11:22:27
问题 Does the following program have undefined behavior in C++17 and later? struct A { void f(int) { /* Assume there is no access to *this here */ } }; int main() { auto a = new A; a->f((a->~A(), 0)); } C++17 guarantees that a->f is evaluated to the member function of the A object before the call's argument is evaluated. Therefore the indirection from -> is well-defined. But before the function call is entered, the argument is evaluated and ends the lifetime of the A object (see however the edits

Why can't I change the 'last write time' of my newly created files?

◇◆丶佛笑我妖孽 提交于 2019-12-31 05:19:05
问题 First off, I'm using Visual Studio 2015's implementation of the Filesystem library from the upcoming C++17 standard, which is based on Boost::Filesystem. Basically, what I'm trying to do is save a file's timestamp (it's "last write time"), copy that file's contents into an archive along with said timestamp, then extract that file back out and use the saved timestamp to restore the correct "last write time". // Get the file's 'last write time' and convert it into a usable integer. __int64