c++20

Does Visual Studio 2019 v16.3.9 fully support C++20?

北城余情 提交于 2020-07-07 06:49:09
问题 I`ve searched a lot and found different inforamation but unfortuantely could not understand Visual Studio 2019 fully supports C++20 or not! According to my searches, there are 3 types of information: Concepts and Modules are fully and partially supported, respectively. There is no support for Couroutines and Ranges . Also, Modules is still at the experimental stage. There is no support except for Concepts . All features are fully supported in MSVC and CLANG. I`ve asked this question because I

How is std::atomic<T>::notify_all ordered?

空扰寡人 提交于 2020-07-06 13:55:48
问题 I expect the below program not to hang. If (2) and (3) are observed in reverse order in (1), it may hang due to lost notification: #include <atomic> #include <chrono> #include <thread> int main() { std::atomic<bool> go{ false }; std::thread thd([&go] { go.wait(false, std::memory_order_relaxed); // (1) }); std::this_thread::sleep_for(std::chrono::milliseconds(400)); go.store(true, std::memory_order_relaxed); // (2) go.notify_all(); // (3) thd.join(); return 0; } So the question is what would

Convert between std::u8string and std::string

喜你入骨 提交于 2020-07-05 01:48:47
问题 C++20 added char8_t and std::u8string for UTF-8. However, there is no UTF-8 version of std::cout and OS APIs mostly expect char and execution character set. So we still need a way to convert between UTF-8 and execution character set. I was rereading a char8_t paper and it looks like the only way to convert between UTF-8 and ECS is to use std::c8rtomb and std::mbrtoc8 functions. However, their API is extremely confusing. Can someone provide an example code? 回答1: At present, std::c8rtomb and

Is pointer arithmetic on allocated storage allowed since C++20?

女生的网名这么多〃 提交于 2020-07-04 11:59:49
问题 In the C++20 standard, it is said that array types are implicit lifetime type . Does it mean that an array to a non implicit lifetime type can be implicitly created? The implicit creation of such an array would not cause creation of the array's elements? Consider this case: //implicit creation of an array of std::string //but not the std::string elements: void * ptr = operator new(sizeof (std::string) * 10); //use launder to get a "pointer to object" (which object?) std::string * sptr = std:

atomic_ref when external underlying type is not aligned as requested

╄→尐↘猪︶ㄣ 提交于 2020-06-27 18:35:08
问题 I read on p0019r8 the following: atomic_ref(T& obj); Requires : The referenced object shall be aligned to required_alignment . cppreference interprets this as UB when not aligned: The behavior is undefined if obj is not aligned to required_alignment. So how would you expect from an implementation to handle it? And implementation can check compile-time alignof , but in reality a type might be aligned more that alignof . An implementation can interpret pointer bits and check runtime alignment,

Check if a class has a possibly-overloaded function call operator

。_饼干妹妹 提交于 2020-06-27 04:11:14
问题 I am wondering whether it would be possible to implement a trait in C++20 to check if a type T is such that it has a possibly overloaded/possibly templated function call operator: operator() . // Declaration template <class T> struct has_function_call_operator; // Definition ??? // Variable template template <class T> inline constexpr bool has_function_call_operator_v = has_function_call_operator<T>::value; so that a code such as the following would lead to the correct result: #include

Why must the return type of a coroutine be move-constructible?

走远了吗. 提交于 2020-06-26 18:06:44
问题 Consider the following code that defines the invoker class - a minimal return type for a coroutine. We explicitly delete the copy and move constructors of the invoker class. #include <coroutine> #include <cstdlib> class invoker { public: class invoker_promise { public: invoker get_return_object() { return invoker{}; } auto initial_suspend() { return std::suspend_never{}; } auto final_suspend() { return std::suspend_never{}; } void return_void() {} void unhandled_exception() { std::abort(); }

Using ranges::view::iota in parallel algorithms

烂漫一生 提交于 2020-06-25 09:40:07
问题 Since there is no index based parallel for algorithm in c++17, I'm wondering if ranges::view::iota can be used in combination with std::for_each to emulate that. That is: using namespace std; constexpr int N= 10'000'000; ranges::iota_view indices(0,N); vector<int> v(N); for_each(execution::par_unseq,indices.begin(),indices.end(),[&](int i) { v[i]= i; }); iota_view seems to provide random access for appropriate types ([range.iota.iterator]): iota_view<I, Bound>::iterator::iterator_category is

Can concepts be used with template template parameters?

你。 提交于 2020-06-25 05:26:09
问题 Let us consider following code: #include <concepts> template<typename X> struct Concrete_M { X f() const { return X{}; } }; struct Concrete_X {}; template<typename T, typename X> concept M = requires (T t) { { t.f() } -> std::convertible_to<X>; }; template<M<Concrete_X>> struct C {}; const C<Concrete_M<Concrete_X>> c{}; Can I use following template template parameter T ? template<template<typename> typename T, typename X> concept M = requires (T<X> t) { { t.f() } -> std::convertible_to<X>; };

placement new on a class with reference field

本小妞迷上赌 提交于 2020-06-25 03:15:33
问题 This is a code example from the C++20 spec ([basic.life]/8): struct C { int i; void f(); const C& operator=( const C& ); }; const C& C::operator=( const C& other) { if ( this != &other ) { this->~C(); // lifetime of *this ends new (this) C(other); // new object of type C created f(); // well-defined } return *this; } int main() { C c1; C c2; c1 = c2; // well-defined c1.f(); // well-defined; c1 refers to a new object of type C } Would the following be legal or undefined behavior : struct C {