Data dodania Pytanie
2017-01-09 21:01 How can I Initialize a div_t Object? »
So the order of the members returned from the div functions seems to be implementation defined. Is quot the 1st member or is rem? Let's say that I'm...
(6) odpowiedzi
2017-01-09 21:01 How can I find the number of arguments a template function takes? »
I have the following type trait: template <class T> struct Arity : Arity<decltype(&T::operator())> {}; template <class T, class R...
(2) odpowiedzi
2017-01-09 16:01 Fastest way to determine value based on boolean c++ »
If you have a boolean b and an int i, which one of the two examples is better? int x = i-1; if(!b)x--; or int x; if(b)x = i-1;else x = i-2; In b...
(2) odpowiedzi
2017-01-09 15:01 Type id of std::string for variable vs. string in argument? »
I referred to http://en.cppreference.com/w/cpp/language/typeid to write code which does different things for different types. The code is as below an...
(3) odpowiedzi
2017-01-09 14:01 Why can std::function be constructed with a lambda with a different return type? »
The following compiles fine: #include <functional> int main() { std::function<const int&()> f = []() -> int {return 1;}; ...
(1) odpowiedzi
2017-01-08 14:01 Why catch block of base class is catching the exception when I am throwing object of derived class? »
if I am passing object of derived class, then the derived class catch block should be invoked. But the output says that the exception is caught by the...
(3) odpowiedzi
2017-01-08 13:01 Valgrind is not showing invalid memory access with incorrectly used c_str() »
Imagine such code: string f() { string r = "ab"; return r; } int main() { const char *c = f().c_str(); printf("%s.\n", c); return 0;...
(1) odpowiedzi
2017-01-08 00:01 Can I abuse a predicate to perform operations on the elements before remove_if removes them? »
I have a std::list of objects. The list is sorted and must stay that way. I need to find those objects that satisfy a certain criterion (I have a pred...
(1) odpowiedzi
2017-01-07 09:01 Is the sub-object of a temporary object guaranteed to be moved on return? »
#include <string> #include <vector> using namespace std; auto f() { vector<string> coll{ "hello" }; // // Must I use ...
(2) odpowiedzi
2017-01-07 00:01 Why is writing to a buffer filled with 42 way faster than writing to a buffer of zeros? »
I would expect writes to a char * buffer to take the same time regardless of the existing contents of the memory1. Wouldn't you? However, while narro...
(1) odpowiedzi
2017-01-07 00:01 May I declare a member type alias to a type in a surrounding scope, using the same name? »
I want a struct to contain a type alias to another type for metaprogramming purposes: struct Foo {}; struct WithNestedTypeAlias { using Foo = Fo...
(1) odpowiedzi
2017-01-06 16:01 A constexpr function with delayed initialization of local variables »
I am trying to write a constexpr function of the form: constexpr int foo(bool cond) { int a, b, c; if (cond) { a = 1; b = 2; ...
(3) odpowiedzi
2017-01-06 15:01 Why does the number of elements in a initializer list cause an ambiguous call error? »
Why are the first two calls to doSomething OK by the compiler, but using two elements in the list causes an ambiguous call? #include <vector> #...
(3) odpowiedzi
2017-01-06 14:01 Can I template user-defined literals? »
Suppose I have some class: template <typename T> class Foo { const T* x_; public: Foo(const T* str) : x_{str} {} }; and I provide some us...
(1) odpowiedzi
2017-01-05 18:01 Inline functions - what are they exactly vis-a-vis the inline keyword? »
In this link, what is an inline function and what is the inline keyword is explained. I'm reading through it because I realized I've never understood ...
(3) odpowiedzi
2017-01-05 18:01 Don't use sizeof for T if T is a function »
I have near following struct for detecting if type can be passed by value: template <class T> struct should_be_passed_by_value { static con...
(4) odpowiedzi
2017-01-05 07:01 push_back/emplace_back a shallow copy of an object into another vector »
Say I have the following code class Car { public: string color; string name; Car(string c, string n): color(c), name(n){}...
(4) odpowiedzi
2017-01-05 04:01 Is it safe to pass arguments by reference into a std::thread function? »
#include <thread> #include <string> #include <vector> #include <chrono> using namespace std; void f(const vector<string&g...
(2) odpowiedzi
2017-01-04 20:01 The first snippet below compiles, but the second doesn't. Why? »
The snippet below compiles (demo): struct A{ int i = 10; }; int main() { struct A{ int i = 20; }; struct A; struct A a; } But this doe...
(3) odpowiedzi
2017-01-04 19:01 C++ Requesting MSVCP110D.dll even if static linked »
I created a dll injection method on my machine in C++ which works very well when I try to inject a specific dll into a game . However , when I run the...
(1) odpowiedzi
2017-01-04 03:01 Implicit conversion from long long to float yields unexpected result »
In an attempt to verify (using VS2012) a book's claim (2nd sentence) that When we assign an integral value to an object of floating-point type, the f...
(2) odpowiedzi
2017-01-03 21:01 Related to C++ and Assembly, what is ebp+8? »
I have the following C++ code: #include <tuple> std::tuple<int, bool> foo() { return std::make_tuple(128, true); } int main() { a...
(1) odpowiedzi
2017-01-03 10:01 Elegant way to get rid of comparison between signed and unsigned integer expressions »
I have the below templates: One is used for unsigned and the other for signed. Is there any elegant way to get rid of the compiler warning without s...
(3) odpowiedzi
2017-01-03 04:01 Why does clang take a string literal as a pointer rather than an array? »
#include <iostream> using namespace std; void f(const char* arg) { cout << "arg is a pointer" << endl; } template<size_t N&...
(2) odpowiedzi
2017-01-02 19:01 What does the "=" operator return? »
From what I understand, C++ works from left to right. For example, if I do: std::cout << "output" << "stream"; C++ first begins at the...
(4) odpowiedzi
2017-01-02 13:01 Function template return type deduction »
I have some class C with const and non-const getters for some generic type Node: template <typename NodeType> class CParent{}; class Node {}; ...
(5) odpowiedzi
2017-01-02 04:01 Looping over file, only get one line »
Say we have a text file with this contents: dogs cats bears trees fish rocks sharks these are just words separated by newline chars. I am trying to...
(1) odpowiedzi
2017-01-02 04:01 Faster way to convert a number from range to another range »
According to this SO question, it is possible to convert a number range to another (linear conversion) by calculating: NewValue = (((OldValue - OldMi...
(1) odpowiedzi
2017-01-02 02:01 Namespace alias in c++ »
I use c++11 while I need some classes from c++17 library. When using boost from which classes were added I wish to do the following: #if __cplusp...
(2) odpowiedzi
2017-01-01 15:01 Are compiler optimization solving thread safety issues? »
I'm writing a C++ multi-threaded code. When testing the overhead of different mutex lock I found that the thread unsafe code seem to yield the corre...
(1) odpowiedzi
2017-01-01 10:01 Insertion operator not producing the expected output? »
Here is the code #include<iostream> using namespace std; main() { cout<<"Hellow World"<<endl; cout.operator<<("Hello...
(2) odpowiedzi
2017-01-01 06:01 C++1z coroutine threading context and coroutine scheduling »
Per this latest C++ TS: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4628.pdf, and based on the understanding of C# async/await language s...
(1) odpowiedzi
2017-01-01 00:01 Is this function call really ambiguous? »
I'm learning about multiple inheritance and the diamond problem, and when I make a function call from the most derived class Visual Studio tells me th...
(3) odpowiedzi
2016-12-31 11:12 How can I retrieve the return type of a function to use in a template? »
I have a function somewhere called x that returns a know value and has known parameters: int x(int y); I have somewhere else, I want to create a co...
(4) odpowiedzi
2016-12-31 11:12 Why does the C++ standard specifically grant leeway regarding memory layout of class data members with different access specifiers? »
The C++11 standard mandates an ordering in memory for the non-static data members of a class but then specifically carves out an exemption for members...
(1) odpowiedzi