gcc trunk now accepts std::tuple t{1, true, "test"s};
% cat tuple.cpp
#include <string>
#include <tuple>
using namespace std::literals::string_literals;
std::tuple t{1, true, "test"s};
% g++ -c -std=c++1z tuple.cpp
%
Posted Oct 7, 2016, 11:25 AM UTC
This does not work :(
(EDIT: it's a bug)
Fortunately, this is actually a bug!
One functionally equivalent thing that I use currently and which works in c++11 is the following:
edit: don't want to take credit, it's taken from this codebase.
This "make idiom" works in many situations where type deduction would be convenient. It's a great fallback.
Correct me if I'm wrong but this could be calling your lambda twice since copy elision is not guaranteed yet. You should put some force inline attribute there.
[deleted]
scope_guardwill execute even if an exception is thrown. Thinktry..finally.Not only that, but in some cases it is required to avoid complex control flow or gotos. Example from my code where scope guard is necessary as f_step could return void (would need an explicit specialization otherwise).
There is a way to call multiple of bases:
Just as a side note, I personally think using
TF::operator()()is much more explicit and easier to read than(*this)():).