c++17

How is P0522R0 breaking code?

混江龙づ霸主 提交于 2021-01-29 07:11:57
问题 Today I was reading the C++17 support page of clang. I've notice something odd. The feature Matching template template parameters to compatible arguments (P0522R0) is marked as partial, because it must be activate through a switch. Their note says: Despite being the the resolution to a Defect Report, this feature is disabled by default in all language versions, and can be enabled explicitly with the flag -frelaxed-template-template-args in Clang 4. The change to the standard lacks a

Where to initialize static const member in c++17 or newer?

試著忘記壹切 提交于 2021-01-29 05:58:11
问题 The questions is where to initialize static const member in c++17 or newer? Please consider the following two solutions for initializing a static const member in c++: Solution 1 (for c++14 or older): //foo.h: #include <iostream> struct foo{ static const std::string ToBeInitialized; }; //foo.cpp #include <iostream> #include "foo.h" const std::string foo::ToBeInitialized{"with a value"}; Solution 2 (for c++17 or newer): //foo.h: #include <iostream> struct foo{ inline static const std::string

Simple division of labour over threads is not reducing the time taken

吃可爱长大的小学妹 提交于 2021-01-29 05:29:48
问题 I have been trying to improve computation times on a project by splitting the work into tasks/threads and it has not been working out very well. So I decided to make a simple test project to see if I can get it working in a very simple case and this also is not working out as I expected it to. What I have attempted to do is: do a task X times in one thread - check the time taken. do a task X / Y times in Y threads - check the time taken. So if 1 thread takes T seconds to do 100'000'000

unexpend for-loop result after change the third part of for-loop

落花浮王杯 提交于 2021-01-29 04:59:37
问题 When I use for-loop in my source file, I get a unexpend result. Here is the minimum source file (I hide the head of file and the function of print_set ): // the main function int main(void) { set<int> test{3, 5}; print_set(test); for (auto it = test.begin(); it != test.end();) { auto node = test.extract(it); ++it; } print_set(test); } Then I use command to compile and run: $ g++ --version g++ (Dedian 8.3.0-6) 8.3.0 ... (not very important infomation for this question) $ g++ -std=c++17 temp

Replacement to getch based code block in cpp

只愿长相守 提交于 2021-01-28 19:52:42
问题 I stumbled upon a code from 2016 written in the Turbo C++ IDE in windows It was to accept passwords char pass; for (length = 0;;) { pass=getch(); if (pass == 13) { break; } if ((pass >= 'A' && pass <= 'Z') || (pass >= 'a' && pass <= 'z') || (pass >= '0' && pass <= '9') || (pass == '!' || '@' || '#' || '$' || '%' || '^' || '&' || '*' || '(' || ')')) { str[length] = pass; ++length; cout << "#"; } } is there any replacement for this without the getch method for linux to show output like this ***

Expose variable from c++ to qml

£可爱£侵袭症+ 提交于 2021-01-28 14:00:37
问题 class Program { public: Program() = delete; Program(const QString &n, const QString &ip); Program(const Program &other) = delete; Program(Program &&other) = default; ~Program() = default; Program &operator=(const Program &other) = delete; Program &operator=(const Program &&other) = delete; constexpr static size_t maxProgram = 99; private: QString name; QString imagePath; }; Hi, I want expose my variable maxProgram from this class to QML, I think thant in the following code its work but I

Can I make expressions constexpr?

牧云@^-^@ 提交于 2021-01-28 11:16:46
问题 I recently wrote some code which prints a function result to cout . The result could have been evaluated at compile time, but it wasn't: #include <algorithm> #include <iostream> constexpr unsigned int gcd(unsigned int u, unsigned int v) { // ... } int main() { std::cout << gcd(5, 3) << std::endl; } For whatever bizarre reason, this compiles to: ( clang -O3 -std=c++17 ) main: push r14 push rbx push rax mov edi, 5 mov esi, 3 call gcd(unsigned int, unsigned int) mov esi, eax ... See Compiler

Validation of an std::initializer_list in constexpr context

一笑奈何 提交于 2021-01-28 09:40:05
问题 I have some class that I would like to be initialized at compile time by an initializer list that needs some level of validation. I first tried static_assert but that wouldn't compile with the error "non-constant condition for static assertion" What is the best way to causing a build error with this? class foo { public: constexpr foo(std::initializer_list<bar> items) { for(auto &&i: items) { if(i == 12) // example validation logic // fail the build } } } constexpr foo foo_list({0,1,2,3,4,5});

Partial specialization failure with GCC

a 夏天 提交于 2021-01-28 06:03:45
问题 After answering this question I decided to dig deeper in the issue to find a minimal and replicable example with same error. Let assume I have the following primary template and I would like to specialize it to std::vector as follows: #include <vector> #include <iostream> template<typename T, typename T::value_type v> struct foo; template<typename T, T v> struct foo<std::vector<T>, v> { static constexpr T value = v; }; int main() { std::cout << foo<std::vector<int>, 32>::value << std::endl;

Partial specialization failure with GCC

泪湿孤枕 提交于 2021-01-28 05:56:35
问题 After answering this question I decided to dig deeper in the issue to find a minimal and replicable example with same error. Let assume I have the following primary template and I would like to specialize it to std::vector as follows: #include <vector> #include <iostream> template<typename T, typename T::value_type v> struct foo; template<typename T, T v> struct foo<std::vector<T>, v> { static constexpr T value = v; }; int main() { std::cout << foo<std::vector<int>, 32>::value << std::endl;