Data dodania Pytanie
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
2017-05-19 00:05 Why do gcc and clang each produce different output for this program? (conversion operator vs constructor) »
program: #include <stdio.h> struct bar_t { int value; template<typename T> bar_t (const T& t) : value { t } {} // e...
(1) odpowiedzi
2017-05-17 06:05 why `S x({})` invoke default constructor in GCC 7/C++1z mode only? »
In the following snippet, GCC 7 with C++1z mode invokes the default constructor, but GCC/C++14 and Clang/C++14,C++1z invoke the initializer-list const...
(1) odpowiedzi
2017-05-15 21:05 Implied anonymous types inside lambdas »
In this question, user @Holger provided an answer that shows an uncommon usage of anonymous classes, which I wasn't aware of. That answer uses stream...
(3) odpowiedzi
2017-05-15 17:05 Overloading structs with template call operator and generic lambdas - gcc vs clang »
I have discovered a code snippet that compiles and works properly in clang++ 4 (and trunk) but fails to compile in g++ 7 (and trunk). Let's assume I h...
(1) odpowiedzi
2017-05-11 16:05 Padding of array-like structs »
Given a struct that contains a sequence of the same fundamental types, like this: struct Vector { float x; float y; float z; }; Can it ...
(1) odpowiedzi
2017-05-11 14:05 Deallocation of memory when argument subexpression of new expression throws »
Dynamic analysis discovered curious memory leak in our code-base. The code in question looks like: Something *p = new Something(getArgument()); whe...
(2) odpowiedzi
2017-05-10 08:05 Using own class name to resolve type in a deduced context »
I answered this question using a C++ construction that I'm not familiar with. I want to know if this is legal or allowed by both g++ (6.3.0) and clang...
(1) odpowiedzi
2017-05-06 21:05 This code, why does it have to show undefined behavior? »
According to this sentence in [lex.phases]1.2 Except for splices reverted in a raw string literal, if a splice results in a character sequence t...
(1) odpowiedzi
2017-05-06 12:05 "Default member initializer needed within definition of enclosing class outside of member functions" - is my code ill-formed? »
#include <utility> struct foo { int x{0}; foo() noexcept = default; void f() noexcept(noexcept(std::declval<foo&>())) {} ...
(0) odpowiedzi
2017-05-03 02:05 Is this considered valid c++11 or c++14? Or is gcc/clang getting it wrong? »
While trying to solve Is it possible to tell if a class has hidden a base function in C++?, I generated this: #include <type_traits> #include &...
(3) odpowiedzi
2017-04-29 19:04 Value category of const int variable captured by lambda »
I have been attempting to understand when and when not a lambda with a capture-default odr-uses a variable with automatic storage duration defined in ...
(0) odpowiedzi
2017-04-28 20:04 How can I apply the [[nodiscard]] attribute to a lambda? »
I want to prevent people from calling the lambda without handling the return value. Clang 4.0 refuses everything I've tried, compiling with -std=c++1...
(1) odpowiedzi
2017-04-26 10:04 Is toString() defined to return this for a java.lang.String? »
Consider String foo = s.toString(); for a non-null java.lang.String instance s. Is this defined to return itself, or is it up to a particular Java...
(3) odpowiedzi
2017-04-25 21:04 Matching alias template as template argument »
Consider the following code: #include <type_traits> template<template<class...> class T, class... U> struct is_specialization_of :...
(2) odpowiedzi
2017-04-22 23:04 Guarantees of reordering of a vector »
Say I have this code: #include <iostream> #include <vector> int main() { std::vector<int> vec {10, 15, 20}; auto itr = ve...
(3) odpowiedzi
2017-04-20 23:04 Deducing class template arguments with a constructor that uses a member type alias »
So apparently this is supposed to work: template<class T> struct C { using value_type = T; C(value_type); }; C c(1); // C<int> A...
(2) odpowiedzi
2017-04-19 23:04 What is lub(null, Double)? »
Table 15.25-B in JLS version 8 says that the type of a conditional expression true ? null : 0.0 is lub(null,Double), where lub appears to be some c...
(2) odpowiedzi
2017-04-19 16:04 "Uninitialized captured reference" error when using lambdas in fold expression - clang vs gcc »
Consider the following code: template <typename F, typename X0, typename X1, typename... Xs> auto fold_left(F&& f, X0&& x0, X1&...
(1) odpowiedzi
2017-04-18 10:04 Why is a const variable sometimes not required to be captured in a lambda? »
Consider the following example: #include <cstdlib> int main() { const int m = 42; [] { m; }(); // OK const int n = std::rand(); ...
(3) odpowiedzi
2017-04-13 00:04 Which compiler, if any has a bug in parameter pack expansion? »
When experimenting with convenient ways to access tuples as containers, I wrote a test program. on clang (3.9.1, and apple clang) it compiles as expe...
(2) odpowiedzi
2017-04-11 15:04 When an automatic variable get out of scope, in what order operations occurs? »
I'm building a simple { mutex, value } pair as follows, and I'd like to check with c++ lawyers if my use case is well defined. Tool definition templ...
(0) odpowiedzi