c++17

How to pass a temporary array to a function in standard C++17

*爱你&永不变心* 提交于 2020-06-18 01:27:29
问题 I have a function of the following signature: void foo(int argc, char const * const argv[]); I would like to call it in a concise way, similar, but not necessary identical as below: foo(3, {"one", "two", "three"}); I know that C supports compound literals just for this purpose (reference). I also know how to solve the problem using templates (reference). However, my problem is slightly different. The function signature is fixed - it normally takes arguments passed to main and the size of the

How to properly invoke a function object within a class template's member function? Visual Studio Compiler Error C2440 is being generated

帅比萌擦擦* 提交于 2020-06-17 14:23:07
问题 This is a follow up to this question found here! Now, that I'm able to instantiate the object. I'm now getting a Visual Studio C2440 Compiler Error... In my original code before it was templated I had a set of member functions that worked on the std::function<double(double)> member object that looked like this: struct SomeStruct { double a_; double b_; SomeStruct(double a, double b) : a_{a}, b_{b} {} }; class SomeClass { private: SomeStruct fields_; size_t n_; std::function<double(double)>

Is an init-declarator a prvalue expression

一曲冷凌霜 提交于 2020-06-16 23:48:20
问题 int c = 0; Consider the above code,thereof, c = 0 is an init-declarator and it's also an expression,Becuase of these rules: init-declarator: declarator initializer(opt) A full-expression is: [...] an init-declarator or a mem-initializer, including the constituent expressions of the initializer, As long as an expression,it will have a value category. A prvalue is an expression whose evaluation initializes an object or a bit-field, or computes the value of the operand of an operator, as

Is an init-declarator a prvalue expression

强颜欢笑 提交于 2020-06-16 23:45:09
问题 int c = 0; Consider the above code,thereof, c = 0 is an init-declarator and it's also an expression,Becuase of these rules: init-declarator: declarator initializer(opt) A full-expression is: [...] an init-declarator or a mem-initializer, including the constituent expressions of the initializer, As long as an expression,it will have a value category. A prvalue is an expression whose evaluation initializes an object or a bit-field, or computes the value of the operand of an operator, as

initializing a static const array inside a class - c++

假装没事ソ 提交于 2020-06-16 03:35:24
问题 Consider the following code, I've marked the important line with #this symbol: #include <glad/include/glad/glad.h> #include <string> #include <iostream> #ifndef LAMP_H #define LAMP_H namespace lmp{ class genLamp{ unsigned int lmpVAO; static const float flag{1}; //#this is allowed static const float default_shape[]{ //#this is not allowed -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, 0.5f, 0.5f, -0.5f, 1.0f, 1.0f, -0.5f, 0.5f, -0.5f, 0.0f, 1.0f

Correct way to ensure sharing with std::hardware_constructive_interference_size

拥有回忆 提交于 2020-06-14 06:43:13
问题 What is the correct and portable way to ensure true sharing in a struct small enough to fit in a cacheline? Is it enough to just ensure that the struct is small enough? Or does it also have to be aligned on the cache boundary? For example, assuming the size of a cacheline is 64 bytes, is the following enough? struct A { std::uint32_t one; std::uint32_t two; }; Or do I have to do this? struct alignas(std::hardware_constructive_interference_size) A { std::uint32_t one; std::uint32_t two; };

tbb:concurrent_hash_map<K,V>: sample code for Intel Threading Building Blocks (TBB)

冷暖自知 提交于 2020-06-13 05:06:19
问题 Looking for sample code to use tbb::concurrent_hash_map<K,V> from Intel Threading Building Blocks (TBB). I can insert, but I cannot seem to read the values back. The official Intel documentation appears to be somewhat lacking on the sample code side. Update The best docs are in "Pro TBB: C++ Parallel Programming with Threading Building Blocks" by Voss. Download this book for free (it's public domain). Ignore the Intel docs. They are essentially a collection of function signatures. 回答1: Intel

tbb:concurrent_hash_map<K,V>: sample code for Intel Threading Building Blocks (TBB)

谁都会走 提交于 2020-06-13 05:06:10
问题 Looking for sample code to use tbb::concurrent_hash_map<K,V> from Intel Threading Building Blocks (TBB). I can insert, but I cannot seem to read the values back. The official Intel documentation appears to be somewhat lacking on the sample code side. Update The best docs are in "Pro TBB: C++ Parallel Programming with Threading Building Blocks" by Voss. Download this book for free (it's public domain). Ignore the Intel docs. They are essentially a collection of function signatures. 回答1: Intel

Why is there no 'aligned_realloc' on most platforms?

江枫思渺然 提交于 2020-06-12 04:42:23
问题 MSVC has its own non-standard functions _aligned_malloc , _aligned_realloc and _aligned_free . C++17 and C11 have introduced (std::)aligned_alloc , results of which can be de allocated with free or realloc . But realloc cannot be used to actually re allocate memory returned by aligned_alloc , since it does not take an alignment parameter and thus cannot guarantee that the returned pointer will be properly aligned. I can't even find any non-standard extensions that could reallocate aligned

Why is there no 'aligned_realloc' on most platforms?

我们两清 提交于 2020-06-12 04:41:56
问题 MSVC has its own non-standard functions _aligned_malloc , _aligned_realloc and _aligned_free . C++17 and C11 have introduced (std::)aligned_alloc , results of which can be de allocated with free or realloc . But realloc cannot be used to actually re allocate memory returned by aligned_alloc , since it does not take an alignment parameter and thus cannot guarantee that the returned pointer will be properly aligned. I can't even find any non-standard extensions that could reallocate aligned