Data dodania Pytanie
2017-10-12 18:10 With VC 15.4.0, std::function assignment produces C2679 (compiled with 15.3.5) »
The following code compiles just fine with VC 15.3.5: #include <Windows.h> #include <string> #include <memory> #include <optiona...
(0) odpowiedzi
2017-10-12 18:10 Performance: Matlab vs C++ Matrix vector multiplication »
Preamble Some time ago I asked a question about performance of Matlab vs Python (Performance: Matlab vs Python). I was surprised that Matlab is faste...
(1) odpowiedzi
2017-10-12 17:10 std::sin change in C++11? »
cppreference includes the following description about the return value of std::sin: The result may have little or no significance if the magnitude...
(1) odpowiedzi
2017-10-12 15:10 sine result depends on C++ compiler used »
I use the two following C++ compilers: cl.exe : Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24210 for x86 g++ : g++ (Ubuntu 5.2.1-22ubuntu...
(3) odpowiedzi
2017-10-12 04:10 How can I read a signed integer from a buffer of uint8_t without invoking un- or implementation-defined behaviour? »
Here's a simple function that tries to do read a generic twos-complement integer from a big-endian buffer, where we'll assume std::is_signed_v<INT_...
(1) odpowiedzi
2017-10-11 21:10 Implicitly virtual constexpr function »
Virtual functions cannot be constexpr however, when a function is implicitly virtual through inheritance, the compilers I have tried don't complain ab...
(1) odpowiedzi
2017-10-11 14:10 `constexpr` variable "used in its own initializer": Clang vs. GCC »
This question seems related to an existing one, but I do not understand the "portable workaround" provided in the answer there (involving const auto t...
(1) odpowiedzi
2017-10-11 11:10 GCC : Unscoped enumeration type give an ambiguity error »
In the following code, I have defined an unscoped enumeration with long long type. This program works fine on Clang. But GCC compiler gives an ambigu...
(1) odpowiedzi
2017-10-10 20:10 Ok to use std::getline() with a moved-from std::string? »
Is it safe and well-defined for the second argument to std::getline(std::istream&, std::string&) to be an lvalue referring to a moved-from std...
(3) odpowiedzi
2017-10-10 10:10 Template argument name collision with method in MSVC C++ »
Following snippet does not compile in MSVC C++ (2015, 2017): template <typename Type> struct Base : public Type { Base(const Type & typ...
(1) odpowiedzi
2017-10-10 09:10 Multiply doubles in Python with same precision as C++ »
I am rewriting a C++ program into Python. I need to multiply 2 doubles but C++ and Python don't give the same result. Here's an example with 'hard-cod...
(3) odpowiedzi
2017-10-09 14:10 Does shared_ptr still own its object when calling the deleter? »
I have a std::shared_ptr with a custom deleter and in that deleter, I would like to take a temporary copy of the original std::shared_ptr. Expressed i...
(1) odpowiedzi
2017-10-09 13:10 Why is C++ more restrictive regarding forward declaration of function prototypes (signatures)? »
I noticed that C++ is more restrictive than C with regards to declaring function signatures before using them even if function definitions are declare...
(5) odpowiedzi
2017-10-09 08:10 Decrement of end of std::map »
Here is my code: #include <iostream> #include <map> using namespace std; int main() { map<int , int > myMap; map<int ...
(2) odpowiedzi
2017-10-08 17:10 Can we use heterogeneous lookup comparator to perform a "partial-match" search on STL associative containers? »
So I was looking at support for heterogeneous lookup in STL's associative containers (since C++14) and got a bit confused about what we can do and wha...
(1) odpowiedzi
2017-10-08 13:10 Is there a way to deduce alias templates to template template parameter while still preserving its property of being deduced context »
After a while I discovered again a power of template template-parameters. See e.g. the following snippet: template <template <class> class T...
(1) odpowiedzi
2017-10-08 09:10 Return by value copies instead of moving »
Why does this program call the copy constructor instead of the move constructor? class Qwe { public: int x=0; Qwe(int x) : x(x){} Qwe(con...
(2) odpowiedzi
2017-10-07 23:10 C++ store functions that forward universal references »
Is it possible to store a function that has similar behaviour to the following function: void target(int foo, size_t bar) {} void target(std::string ...
(2) odpowiedzi
2017-10-07 23:10 Is it safe to serialize POD data by casting directly to char array? »
Suppose that T is a POD type that doesn't contain a pointer, and I want to serialize T (in addition to some other data too). I've created the below fu...
(3) odpowiedzi
2017-10-07 20:10 Are user defined deduction guides involving template template parameter as a template for guidance standard compliant »
Background Yesterday I asked a question about the guarantees of deduction guides usage in case of template template parameters. I was really surprise...
(0) odpowiedzi
2017-10-07 14:10 What is the idiomatic cpp14 way to read an int32_t from a char* buffer? »
Given a char buffer c containing an int (little endian). How to read it as int32_t? I wrote this code but it doesn't feel idiomatic cpp. int32_t v;...
(4) odpowiedzi
2017-10-06 18:10 Is it guaranteed that template template parameter invoke user provided deduction guides »
Consider an example: #include <type_traits> #include <string> template <template <class> class TT> //#1 struct Foo { stat...
(1) odpowiedzi
2017-10-06 17:10 c++ template type deduction fail in cast operator »
I have simplified my somewhat more difficult problem to this: http://coliru.stacked-crooked.com/a/2660b33492651e92 #include <iostream> #includ...
(2) odpowiedzi
2017-10-06 09:10 Initialize all the elements of an array to the same number »
Some time ago my old teacher posted this code saying that it is another way to initialize an array to the same number (other than zero of course). Th...
(7) odpowiedzi
2017-10-05 11:10 How to use std::is_volatile? »
I am trying to disallow a specific operation on volatile types. To accomplish this I am trying to use std::is_volatile, but the code below is compilin...
(3) odpowiedzi
2017-10-05 08:10 Doesn't compiler give an ambiguous error for "const" and "not-const" functions »
I have overloaded const and non-const functions in c++ structure. Then, I have run the program and I wondered, it's working fine without ambiguous err...
(3) odpowiedzi
2017-10-05 05:10 Do typedef and using cause a template instantiation? »
Say I have a template class defined like this template <typename T> class Temp{ // irrelevant }; I can either implicitly or explicitly in...
(1) odpowiedzi
2017-10-04 21:10 Timing vs the "as-if" rule »
There is a great question about the "as-if" rule in general, but I wonder if there are any excpetions when it comes to measuring time. Consider this ...
(2) odpowiedzi
2017-10-04 20:10 Auto range based structured bindings with vector »
I'm trying to loop over a vector of tuples: std::vector<std::tuple<int, int, int>> tupleList; By using a range based for loop with stru...
(1) odpowiedzi
2017-10-04 10:10 Testing if two templates are the same, even with non-type parameter packs as parameters »
So I need to find out if two templates are the same, even if the parameters are not, ie. if in T<A> and U<B> T and U are the same, even if...
(2) odpowiedzi
2017-10-04 02:10 Partial template specialization with mismatching `int` and `size_t` not compiling »
With reference to the following code #include <utility> #include <cassert> template <typename T> struct Wot; template <int... ...
(1) odpowiedzi
2017-10-03 23:10 How to #import inside a #define »
I'm working on an Objective-C wrapper around a C++ library, whose source I neither control nor modify. The headers I import trigger various compiler w...
(1) odpowiedzi
2017-10-03 18:10 To support move semantics, should function parameters be taken by unique_ptr, by value, or by rvalue? »
One of my function takes a vector as a parameter and stores it as a member variable. I am using const reference to a vector as described below. class...
(4) odpowiedzi
2017-10-03 13:10 Why is the construction of std::optional<int> more expensive than a std::pair<int, bool>? »
Consider these two approaches that can represent an "optional int": using std_optional_int = std::optional<int>; using my_optional_int = std::p...
(4) odpowiedzi
2017-10-03 11:10 Why does the disjunction assignment operator |= not work with vectors of bools? »
If I have a vector<bool> vec_bool then I cannot modify the contents of the vector using the |= assignment operator. That is, the lines vec_bool...
(1) odpowiedzi