Skip to content

Instantly share code, notes, and snippets.

@jen6
Created December 30, 2015 02:14
Show Gist options
  • Save jen6/ae6695df4660dce4fa6d to your computer and use it in GitHub Desktop.
Save jen6/ae6695df4660dce4fa6d to your computer and use it in GitHub Desktop.
template <class _Ty>
struct _Tuple_val
{
constexpr _Tuple_val()
: _Val()
{ //default construct
}
template<class _Other>
constexpr _Tuple_val(_Other&& _Arg)
: _Val(std::forward<_Other>(_Arg))
{
}
//assign
template<class _Other>
_Tuple_val& operator=(_Other&& _Right)
{
_Val = std::forward<_Other>(_Right);
return (*this);
}
_Ty _Val;
};
//tuple template class
template<class... _Types>
class tuple;
template<>
class tuple<>
{//empty tuple
public:
typedef tuple<> _Myt;
constexpr tuple() noexcept
{
}
};
template<class _This,
class... _Rest>
class tuple<_This, _Rest...>
:private tuple<_Rest...>
{
public:
//recursive definition
typedef _This _This_type;
typedef tuple<_This, _Rest...> _Myt;
typedef tuple<_Rest...> _Mybase;
static const size_t _Mysize = 1 + sizeof...(_Rest);
constexpr tuple()
: _Mybase(),
_Myfirst()
{
}
constexpr explicit tuple(const _This& _This_arg,
const _Rest&... _Rest_arg)
: _Mybase(_Rest_arg...),
_Myfirst(_This_arg)
{
}
constexpr _Mybase& _Get_rest() noexcept
{
return (*this);
}
tuple(const _Myt&) = default;
tuple(_Myt&&) = default;
_Tuple_val<_This> _Myfirst;
};
int main()
{
tuple<> a;
int b = 3;
tuple<int, char, float> c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment