c++17

Structure padding with union members of std::bitset

给你一囗甜甜゛ 提交于 2019-12-13 23:56:36
问题 After I had solved my issue to this question I went on to expand this version of my code to incorporate the unions of the data fields from my previous template versions with this version and I have this so far: main.cpp #include <iostream> #include <type_traits> #include "Register.h" int main() { using namespace vpc; std::cout << std::boolalpha; std::cout << "std::bitset<64> is trivially copyable " << std::is_trivially_copyable<std::bitset<64>>::value << '\n' << "QWord is trivially copyable "

Storing arbitrary function objects into a class member container without knowing their declaration signature

房东的猫 提交于 2019-12-13 17:22:50
问题 I have a class template, and I do not know if I need to have as one of its arguments class Func or not. I also do not know if I can arbitrarily store a std::function directly into a container without its template argument parameter list. My class looks something like: template<class Data, class Func> class ThreadManager final { private: std::vector<std::shared_ptr<Data>> storedDataPtrs; std::vector<std::shared_ptr<std::thread>> storedThreadPtrs; // Is this valid? I know that `std::function is

Compile error with decltype of iterator de-reference

吃可爱长大的小学妹 提交于 2019-12-13 14:51:59
问题 What am I missing here? Why can't I use decltype to define the value_type of an iterator? The code below gets inscrutable compile-time errors when I use decltype rather than iterator_traits, but only if I also use value_type to declare a vector. Visual Studio 2017, C++17 rev. 15.6 Preview #include <vector> template<class Ptr > void foo(Ptr beg) { *beg = 1; // Cool, babies. // using value_type = decltype(*beg); // COMPILER ERROR when buf declared below using value_type = typename std::iterator

Are there any predefined concepts in Concepts TS?

心不动则不痛 提交于 2019-12-13 14:22:49
问题 'Concepts lite' were already accepted as a TS and (example implementation) merged into GCC main branch, so the follow up question is will any concepts come predefined (like Sortable or Random_access_range )? Where do I look for such predefined concepts? Is the list at cppreference.com an acurate and exhaustive list? Can I use them with the latest GCC trunk build? Edit 1 : Changed C++17 to TS due to concepts not being accepted into C++17. 回答1: There are no concepts defined in the Concepts TS

Difference between references and values in deduction guides

会有一股神秘感。 提交于 2019-12-13 14:19:32
问题 Considering type A : template <typename T, size_t N> struct A { T arr[N]; }; Is there any difference between C++17 user-defined deduction guides template <typename T, typename ... Ts> A(const T&, const Ts& ...) -> A<T, 1 + sizeof...(Ts)>; and template <typename T, typename ... Ts> A(T, Ts ...) -> A<T, 1 + sizeof...(Ts)>; ? Or, in other words is there any difference between const references and values in deduction guides? Please note that the question is not about template function type

Clang++ -fmodules errors using types after #include <cstdint>

萝らか妹 提交于 2019-12-13 13:16:49
问题 The following simple test case file is giving me a compile-time error with the tip of 'master' from Clang's github mirror, when compiled with -fmodules , using the command shown below. I'm wondering if this is a bug with the new experimental Module feature for Clang -- maybe a problem with the implementation of module maps for the standard library -- or if there's something I'm doing wrong. The error still appears if I add -fbuiltin-module-map to the command. Interestingly, the error no

Constructor instantiation in a world of guaranteed copy elision

我怕爱的太早我们不能终老 提交于 2019-12-13 13:05:30
问题 Consider this example: template <typename T> using type = typename T::type; template <typename T> struct A { A(type<T>); }; A<int> f(); A<int> g() { return f(); } Neither gcc nor clang compile this code due to int not having a nested type typedef. But why is that constructor being instantiated at all? f() is a prvalue of the same type as the return of g() , there shouldn't even be a move there. What is causing us to instantiate the bad constructor? 回答1: The constructor is a bit of a red

error: 'string_view' is not a member of 'std'

戏子无情 提交于 2019-12-13 12:40:34
问题 i am new to c++. i compiled my code in visual-studio-code in windows10, with 2 variables of type string and string_view. string variable is fine, but string_view is giving errors.I also enable c++17 extension in configuration.json and edit configuration/ui file in vscode. Here is my code:= #include<iostream> #include<string_view> using namespace std; int main(){ string str="hello"; cout<<str<<endl; std::string_view sv=" world"; auto result=str+sv.data(); return 0; } errors are:= main.cpp: In

What is the auto Bracketed List Syntax?

可紊 提交于 2019-12-13 12:14:49
问题 W.F. gave a now-deleted answer to my question here which used the line: auto [x, y] = div_t{ 1, 0 }; From the code in the answer it looks like that's like a tie for the div_t struct. I was hoping that someone could explain what was going on here. The complete function code was as follows: constexpr bool first_quot() { auto [x, y] = std::div_t{1, 0}; (void)y; return x; } 回答1: In the most most recent draft of the C++17 specification it's called "Decomposition declarations" and is defined in

Why C++ implicit type conversion work's well with structures but in other way with classes

a 夏天 提交于 2019-12-13 10:31:06
问题 I'm trying to create a multi-dimensional array with dynamic memory initialisation in C++, but an implicit type conversion works in one way when I work directly with functions, but in another way when I tried to create class-shell around this pointer and named functions as class members. If template type T, for example, int, with structures it prefers (T *&) type over (T &) for a pointer of any nesting, but when I made these functions class members, they even can't implicitly make T** to (T*&)