Reputation: 879
I have a pressing need for the function std::forward_as_tuple
, but am restricted to using GCC 4.5.0 (I know this is a bad situation to put oneself into, but it would solve a lot of problems for me, so please keep the snarky remarks to a minimum). The <tuple>
header does not seem to contain the function (as it should), so my question is:
Upvotes: 4
Views: 613
Reputation: 171303
Is it hidden in some other header? (This has happened before, but is hard to determine.)
What's hard about grep
?
The
<tuple>
header does not seem to contain the function (as it should)
std::forward_as_tuple
was originally called std::pack_arguments
and was proposed in N3059 in March 2010 and first appeared in the N3092 working draft. GCC 4.5.0 was released in April 2010 when the ink was barely dry on that draft.
Feel free to try and use C++11 features in an unmaintained, pre-C++11 compiler, but it's a bit unfair to say it should include features that didn't even exist when the release branch was cut and being prepared for a new release!
You should at least use GCC 4.5.4, using a dot-oh release is just asking for trouble, it will be full of new bugs that are fixed in later 4.5.x releases (although it still doesn't include forward_as_tuple
or pack_arguments
, they first appeared in GCC 4.6)
You could consider using boost::tuple
instead, which attempts to provide a feature-complete implementation even for older compilers.
Upvotes: 1
Reputation: 7129
Implementation is simple:
template <typename... Elements>
/*constexpr*/ tuple<Elements&&...>
forward_as_tuple(Elements&&... args) /* noexcept */
{
return tuple<Elements&&...>(std::forward<Elements>(args)...);
}
Don't know in which GCC it appears. According this document variadic templates and rvalue refs are available since gcc 4.3, so it should work for your gcc 4.5 (I hope)
Upvotes: 5