Data dodania Pytanie
2017-07-26 07:07 Why is template parameter pack used in a function argument type as its template argument list not able to be explicit specified »
I have the following piece of code: template <typename, typename> struct AAA{}; template<typename ...Args> void f(AAA<Args...> *) ...
(5) odpowiedzi
2017-07-25 17:07 how to get enum value from enum type? »
The question in the title may sound trivial, so I better explain with some code what I want to do... In C++11 I can do this: #include <iostream&g...
(2) odpowiedzi
2017-07-25 13:07 Sorting a list with a comparison function that doesn't follow 'strict weak ordering' »
I have a list of 10 items. I would like sort them in a particular manner. For eg. the items are A1, B, C1, A2, A3, F, G, C2, H, A4 Rules are C sho...
(5) odpowiedzi
2017-07-25 11:07 How to write portable simd code for complex multiplicative reduction »
I want to write fast simd code to compute the multiplicative reduction of a complex array. In standard C this is: #include <complex.h> complex ...
(3) odpowiedzi
2017-07-24 23:07 Bit trick to detect if any of some integers has a specific value »
Is there any clever bit trick to detect if any of a small number of integers (say 3 or 4) has a specific value? The straightforward bool test(int a,...
(3) odpowiedzi
2017-07-24 13:07 C++ - Return const unique_ptr »
I am wondering why I get an error when compiling: const std::unique_ptr<int> get() { return std::make_unique<int>(10); } int main()...
(1) odpowiedzi
2017-07-24 12:07 Why can static member function definitions not have the keyword 'static'? »
As per this link on the 'static' keyword in C++ : The static keyword is only used with the declaration of a static member, inside the class defi...
(4) odpowiedzi
2017-07-23 18:07 Why is std::allocator a template? »
The job of an allocator is to obtain "raw" memory via its allocate method. What the caller constructs in the memory returned by the allocator is of no...
(2) odpowiedzi
2017-07-23 17:07 Why disallow goto in constexpr functions? »
C++14 has rules for what you can and can't do in a constexpr function. Some of them (no asm, no static variables) seem pretty reasonable. But the Stan...
(2) odpowiedzi
2017-07-23 12:07 Does C copy the element every time you access an array? »
C can't return references unlike C++. Does that mean if you access A[i] it will copy the element in evaluating the expression? For example if A is an...
(5) odpowiedzi
2017-07-22 22:07 Why does Clang warn about unused pointers and unused primitives, but not unused objects? »
In this code snippet... sf::Time obj; sf::Time* ptr; int i; int* p2; The first line doesn't produce a warning, but the other three do. How come? (...
(1) odpowiedzi
2017-07-22 20:07 Set stack size programmatically on Windows »
Is it possible in WinAPI to set stack size for the current thread at runtime like setrlimit does on Linux? I mean to increase the reserved stack size ...
(2) odpowiedzi
2017-07-22 13:07 Why do std::generate() and std::generate_n() require different iterators? »
I was looking at generate() and generate_n() in cppreference and am trying to understand why does generate() require ForwardIterator, whereas generate...
(3) odpowiedzi
2017-07-21 18:07 How to eager commit allocated memory in C++? »
The General Situation An application that is extremely intensive on both bandwidth, CPU usage, and GPU usage needs to transfer about 10-15GB per seco...
(1) odpowiedzi
2017-07-21 08:07 SFINAE: decltype on operator[] »
Based on answers here and here I am trying to use the following template <typename T> using operator_square_brackets = decltype(&T::operato...
(1) odpowiedzi
2017-07-21 00:07 Create bitmask based on a pattern as constexpr »
I would like to implement a template function which generates bitmasks in compile-time for integral types. These masks should be based on 8-bit patter...
(6) odpowiedzi
2017-07-20 23:07 Efficient way of slicing large image into 10x10 images (opencv) »
I have a large 2400x1300 png file that I want to slice up into 10x10 pixel ordered images and save them into a separate file. I have found multiple me...
(1) odpowiedzi
2017-07-20 20:07 Finding whether a signed and an unsigned integer are both even or both odd »
I have an int m and an unsigned int j and want to determine whether they are both even or both odd. In the past I've been using if((int(j)+m)%2) t...
(7) odpowiedzi
2017-07-20 16:07 Does std::map assign its comparator? »
Is std::map copy assignment (in style map1 = map2;) required to copy comparator of map2 to map1? I have tested that actual implementations do that. ...
(2) odpowiedzi
2017-07-20 16:07 Initializing a vector of auto (unknown) type inside a template function in C++ »
I have a template function inside which I want to generate a vector which is of an unknown type. I tried to make it auto, but compiler says it is not ...
(7) odpowiedzi
2017-07-19 17:07 Difference between sizeof(empty struct) and sizeof(struct with empty array)? »
I have two structs defined as follows: struct EmptyStruct { }; struct StructEmptyArr { int arr[0]; }; int main() { printf("sizeof(EmptyStru...
(2) odpowiedzi
2017-07-19 13:07 Bit count : preprocessor magic vs modern C++ »
Suppose that I want to create a compile time constructed bit count lookup table for 64bit integers in 16 bit chunks. The only way I know to do this is...
(3) odpowiedzi
2017-07-19 09:07 What's the difference between static constexpr and static inline variables in C++17? »
With C++17 we get inline variables. One of use for them is to define constant fields in classes. So what's the difference between these two constant...
(1) odpowiedzi
2017-07-18 21:07 Is std::to_string thread safe? »
I am looking to convert integer types to string using std::to_string, but I saw this paragraph: std::to_string relies on std::locale for formattin...
(1) odpowiedzi
2017-07-18 14:07 Fill std::map with std::generate_n »
I'd like to fill a std::map using std::generate_n but can't get it to work. What I tried is something along these lines: unsigned number_of_pairs{5};...
(2) odpowiedzi
2017-07-18 11:07 Protect CRTP pattern from stack overflowing in "pure virtual" calls »
Consider the following standard CRTP example: #include <iostream> template<class Derived> struct Base { void f() { static_cast<De...
(4) odpowiedzi
2017-07-17 13:07 Why does std::vector enforce copy on initialization? »
I have a copy/move probing class: #include <iostream> struct A { A() { std::cout << "Creating A" << std::endl; ...
(1) odpowiedzi
2017-07-17 12:07 Why can't constructors be explicitly called while destructors can? »
In the following C++ code, I am allowed to explicitly call the destructor but not the constructor. Why is that? Wouldn't be explicit ctor call more ex...
(3) odpowiedzi
2017-07-17 07:07 Is std::byte well defined? »
C++17 introduces the std::byte type. A library type that can (supposedly) be used to access raw memory, but stands separate from the character types a...
(2) odpowiedzi
2017-07-16 17:07 Constructor is always used instead of explicit conversion operator »
I have the following class: template <typename T1> class Foo { public: Foo(T1* obj) : obj(obj) {} template <typename T2> Foo...
(2) odpowiedzi
2017-07-16 08:07 When can an object have either but not both of non zero size , one or more bytes of storage? »
C++ 14 intro.cpp States: a most derived object shall have a non-zero size and shall occupy one or more bytes of storage Why did they have to state ...
(2) odpowiedzi
2017-07-16 06:07 Does std::vector::emplace() really offer the strong exception guarantee in the face of a throwing move constructor/assignment operator? »
According to cppreference.com, std::vector::emplace() offers the strong exception guarantee unconditionally: If an exception is thrown (e.g. by th...
(1) odpowiedzi
2017-07-15 22:07 What is the purpose of extern C AND C++ for a single function (bsearch / qsort)? »
When browsing through a draft of the standard (N4527), I found the following paragraph ([alg.c.library]): The function signature: bsearch(const v...
(1) odpowiedzi
2017-07-15 19:07 Custom allocator for std::bind »
Perhaps the topic of std::bind and std::function is not clear enough to me - then, please, clarify. I'm trying to implement a thread pool (like this),...
(0) odpowiedzi
2017-07-15 13:07 Mystifying UB/segfault only on gcc - is the code ill-formed? »
#include <utility> template <typename P, typename F> struct foo { P _p; int i{0}; foo(P&& p, F) : _p{std::move(p)} {...
(0) odpowiedzi