c++14

Why doesn't function declared inside other function participate in argument dependent lookup?

自古美人都是妖i 提交于 2019-12-04 04:43:09
Consider a simple example: template <class T> struct tag { }; int main() { auto foo = [](auto x) -> decltype(bar(x)) { return {}; }; tag<int> bar(tag<int>); bar(tag<int>{}); // <- compiles OK foo(tag<int>{}); // 'bar' was not declared in this scope ?! } tag<int> bar(tag<int>) { return {}; } Both [gcc] and [clang] refuses to compile the code. Is this code ill-formed in some way? From unqualified lookup rules ([basic.lookup.unqual]): For the members of a class X , a name used in a member function body, [...], shall be declared in one of the following ways — if X is a local class or is a nested

lambda capture during initialization should be an error

寵の児 提交于 2019-12-04 04:17:24
问题 What I'm trying to do is eat exceptions when constructing an object that may be invalid. It'd be perfect for use of std::optional , but I don't believe the omission of std::optional changes the error I see: the object is being captured and used before it's been initialized. I don't believe it should be captured in the first place because we haven't reached a sequence point to the best of my knowledge (does a lambda initialization count as a sequence point?). Moreover, the bug is IMO easily

Why forwarding return value is needed

微笑、不失礼 提交于 2019-12-04 03:58:21
In the doc of std::forward , it gave the following example: template<class T> void wrapper(T&& arg) { foo(forward<decltype(forward<T>(arg).get())>(forward<T>(arg).get())); } Why is forwarding of return value needed here? What's the cases where it is different to the following code: template<class T> void wrapper(T&& arg) { foo(forward<T>(arg).get()); } Let's break down the possibilities. T::get could return an lvalue reference (which is an lvalue expression), an rvalue reference (which is an xvalue expression), or a prvalue. The forward expression will convert the lvalue expression into... an

Switching back and forth between Array of Structures (AoS) and Structure of Arrays (SoA)

倾然丶 夕夏残阳落幕 提交于 2019-12-04 03:42:17
One feature that plays a prominent role in many of the writings on data oriented design is that there are many cases where rather than AoS (array of structs): struct C_AoS { int foo; double bar; }; std::vector<C_AoS> cs; ... std::cout << cs[42].foo << std::endl; it is more efficient to arrange one's data in SoA (struct of arrays): struct C_SoA { std::vector<int> foo; std::vector<double> bar; }; C_SoA cs; ... std::cout << cs.foo[42] << std::endl; Now what I am looking for is a solution which would allow me to switch between AoS and SoA without changing the calling interface, i.e. that I could,

Return type deduction for class methods? C++1y

别来无恙 提交于 2019-12-04 03:30:18
问题 Is return type deduction allowed for member functions in c++14, or only for free functions? I ask because I sort of implicitly assumed it would work, but in gcc 4.8.1 I get an internal compiler error("in gen_type_die_with_usage"). First time I have ever gotten such a cryptic error like that, so I am a bit skeptical; and I know they have changed the spec since then. For clarity this works for me: auto foo() {return 5;} but this doesn't: class Bar{ auto baz() {return 5;} } Is this allowed in

About ODR-violations and template variables

不打扰是莪最后的温柔 提交于 2019-12-04 03:25:19
I know that template functions don't suffer of multiple definitions when linking, like member functions defined inside a class, which are inline by default. Also, constexpr objects have internal linkage, but template variables have external linkage (I mean at namespace scope and for C++14 in both cases). What about? template<class T> constexpr T i_am_odr_safe{}; Does i_am_odr_safe have external or internal linkage in C++14? and is it safe regarding multiple-definitions like function templates? In other words, is i_am_odr_safe odr-safe? This is core issue 1713 , the direction of which IIRC is

How to check whether T is an aggregate type?

℡╲_俬逩灬. 提交于 2019-12-04 03:23:20
问题 I know about std::is_pod . But it checks more than just aggregate types. Or, is std::is_pod just the best we can do? Basically, I want to write a function template for this: template <typename T> aggregate_wrapper<T> wrap(T&& x); which is only enabled when T is an aggregate type. 回答1: There is no way to synthesize an is_aggregate template. The rules for whether something participates in aggregate initialization cannot be detected by C++14 metaprogramming techniques (they would require

How to write a generic variadic lambda that discards its parameters?

我与影子孤独终老i 提交于 2019-12-04 03:22:44
问题 I want to write a lambda that takes an arbitrary number of arguments by universal reference and ignores them entirely. The obvious method would be to use the syntax for a variadic universal parameter pack and omit the parameter name: auto my_lambda = [](auto&&...) { return 42; }; This works fine (with gcc 4.9.2) until I try to pass a non trivially-copyable object: struct S { S() {} S(S const&) {} }; my_lambda("meow", 42, S{}); ^ error: cannot pass objects of non-trivially-copyable type

SFINAE and noexcept specifier

北战南征 提交于 2019-12-04 03:04:45
Does an expression in noexcept specifier's parentheses participate in SFINAE during overload resolution of function templates? I want to make an wrapper for aggregates and want the std::is_constructible predicate to work properly for it: template< typename type > struct embrace : type { template< typename ...arguments > embrace(arguments &&... _arguments) noexcept(noexcept(type{std::forward< arguments >(_arguments)...})) : type{std::forward< arguments >(_arguments)...} // braces { ; } }; int main() { struct S { int i; double j; }; // aggregate using E = embrace< S >; E b(1, 1.0); //

How to Compile C++14 code for Android?

此生再无相见时 提交于 2019-12-04 02:46:21
Is it possible to compile C++14 source code for Android with ndk10d? I've tried both g++ and clang compilers but it seems that -std=c++14 -std=c++1y flags do not work. If I use c++_static as my APP_STL, i get the following error: User/someone/Software/Android/android-ndk-r10d/platforms/android-17/arch-arm/usr/include/locale.h:55:1: error: empty struct has size 0 in C, size 1 in C++ Edit: I am using Mac OSX 10.10.4 with Xcode 6.3.2 (able to compile C++14 for iOS). I use android-ndk-r12b-windows-x86_64 , compile success with -std=c++14 Android.mk LOCAL_CPPFLAGS = -Wall -std=c++14 If someone