Created
December 30, 2015 02:14
-
-
Save jen6/ae6695df4660dce4fa6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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