Data dodania Pytanie
2017-08-08 08:08 Is copy/move elision allowed when returning *&object? »
Look at this code: #include <stdio.h> struct Foo { Foo() { } Foo(const Foo &) { printf("copy\n"); } Foo(Foo &&) { prin...
(1) odpowiedzi
2017-08-07 19:08 C++17 And the Current State of Decimal Floating Point »
What is the current status of decimal floating point in C++? I am specifically looking for the status of language inclusion, standards compliance and...
(1) odpowiedzi
2017-08-06 14:08 Why does this rvalue reference bind to an lvalue? »
I do not understand why the following code compiles on GCC 8.0: decltype(auto) foo(int&& r) { return r; } In foo, the declaration type ...
(1) odpowiedzi
2017-08-05 08:08 Special behavior for decltype of call operator for incomplete types »
I've been struggling with a compilation issue, and have been able to shrink the problem down to a small code segment. To set the stage, I'm trying to...
(1) odpowiedzi
2017-08-04 14:08 Consequences of uninitialised variables: int vs unsigned char »
I saw the following example on cppreference.com int x; // OK: the value of x is indeterminate int y = x; // undefined behavio...
(4) odpowiedzi
2017-08-02 10:08 Is this a clang bug or something I don't know about C++? »
While looking at this question I tried it out with clang and got in a weird situation. The following example: #include <string> class ACP { pu...
(1) odpowiedzi
2017-07-26 18:07 Are structs of variables of the same type layout compatible with a struct containing an array of that type? »
Are these 2 structs layout-compatible? struct One { float x, y, z; }; struct Two { float c[3]; }; Both contains 3 floats, so in a way, thi...
(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-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-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-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-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-13 07:07 Why can't a destructor be marked constexpr? »
In C++, you can declare many things as constexpr: variables, functions (including member functions and operators), constructors, and since C++1z, also...
(4) odpowiedzi
2017-07-05 21:07 Is ...foo an operator or syntax? »
I've heard ... referred to both as 'spread syntax' and 'the spread operator', with the latter being a lot more popular. The URL of the relevant MDN do...
(2) odpowiedzi
2017-07-04 17:07 Can the compiler exploit empty base optimisation if the class contains a member of the base class? »
Consider struct base {}; struct child : base {}; It's well-known that sizeof(child) can be 1 by application of the empty base optimisation. Now ho...
(3) odpowiedzi
2017-07-03 11:07 Geometric distribution with p = 1 »
I found in the standard that the std::geometric distribution requires 0 < p < 1 for its termination probability and that std::negative_binomial_...
(0) odpowiedzi
2017-07-01 11:07 Is int main(void) valid in C++? »
C++ standard lists allowed forms of main. It doesn't list int main(void) as an allowed form. But, it generally states that The parameter list (vo...
(2) odpowiedzi
2017-06-28 12:06 Is `std::array<T, 0>` default constructible where `T` is not default constructible? »
Consider the code below: #include <array> struct T { T() = delete; }; int main() { std::array<T, 0> a; a.size(); } We def...
(3) odpowiedzi
2017-06-27 01:06 What is the difference between a sequence point and operator precedence? »
Consider the classical sequence point example: i = i++; The C and C++ standards state that the behavior of the above expression is undefined becaus...
(2) odpowiedzi
2017-06-22 13:06 Is decltype(auto) for a structured binding suppose to be a reference? »
Consider an example: #include <iostream> #include <type_traits> #include <tuple> int main() { auto tup = std::make_tuple(1, 2)...
(1) odpowiedzi
2017-06-22 11:06 structured bindings: when something looks like a reference and behaves similarly to a reference, but it's not a reference »
Yesterday I've seen an interesting question here on SO about structured binding. We can sum up it as it follows. Consider the example code below: #in...
(2) odpowiedzi
2017-06-11 17:06 Will I be able to declare constexpr lambda inside a template parameter »
I know it's like opening the Pandora box but it doesn't stop bothering me. Consider a simple example: #include <type_traits> template <auto...
(1) odpowiedzi
2017-06-10 17:06 I believe this is a bug in clang++ related to the access to a class's public member function »
The following doesn't compile in clang: #include <iostream> void f() { std::cout << "f()\n"; } struct S { typedef void(*p)(); o...
(1) odpowiedzi
2017-06-08 09:06 Overload resolution for multiply inherited operator() »
First, consider this C++ code: #include <stdio.h> struct foo_int { void print(int x) { printf("int %d\n", x); } }; struct...
(3) odpowiedzi
2017-06-07 17:06 Is this-> mandatory to access Base<T> identifiers from derived classes? »
This code compiles with MSVC 2015, but doesn't compile with Clang 5.0.0 (trunk 304874): template <typename T> struct Base { T data; }; templ...
(2) odpowiedzi
2017-06-07 14:06 Non-capturing lambda seems to nevertheless capture the enclosing instance »
I wrote this code: import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.function.Supplier; public class Main { publi...
(2) odpowiedzi
2017-06-02 00:06 Why are arbitrary target expressions allowed in for-loops? »
I accidentally wrote some code like this: foo = [42] k = {'c': 'd'} for k['z'] in foo: # Huh?? print k But to my surprise, this was not a syn...
(4) odpowiedzi
2017-06-01 17:06 Is the move constructor called after invoking a conversion function? »
Consider this example: struct T { }; struct S { operator T(); }; S s; T t = s; [dcl.init] will take us to [over.match.copy] which will find t...
(1) odpowiedzi
2017-05-31 23:05 Dependent type or argument in decltype in function definition fails to compile when declared without decltype »
I've been playing with deduced return types in definitions that resolve to the same type as the declaration. This works: template <typename> st...
(0) odpowiedzi
2017-05-30 18:05 Is stateful metaprogramming ill-formed (yet)? »
One of my most beloved/evil inventions I've had the fortune to come across is the constexpr counter, aka stateful metaprogramming. As mentioned in the...
(1) odpowiedzi
2017-05-27 19:05 Perfect forwarding of variables declared with structured binding »
I have a struct template <typename T> struct Demo { T x; T y; }; and I'm trying to write a generic function similar to std::get for t...
(2) odpowiedzi
2017-05-26 21:05 Extending the life of a temporary object by getting a reference to a subobject »
There is a subtle difference between the language used at cppreference.com and by the C++11 Standard regarding when the life of a temporary object is ...
(0) odpowiedzi
2017-05-25 12:05 Why can't I access static methods of an interface using an instance variable »
Why can't I access static methods of an interface using an instance variable. public class TestClass { public static void main(String[] args) { ...
(1) odpowiedzi
2017-05-24 11:05 What changes to C++ made copy initialization work for class with explicit constructor? »
Consider this code: struct X{ explicit X(){} explicit X(const X&){} }; void foo(X a = X()){} int main(){} Using C++14 standard, both ...
(1) odpowiedzi
2017-05-20 20:05 Why Can't Member Variables Be Used Unqualified In A Lambda If Non-Captured Local Variables Exist? »
Simple example: class Foo { int x; void bar(int x) { [this]() -> void { x = 6; }(); } }; This doesn't c...
(0) odpowiedzi