Created
May 10, 2014 04:20
-
-
Save Fuyutsubaki/6803bd43553db89d0d32 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
#include<iostream> | |
#include<string> | |
namespace iod | |
{ | |
template<class...> | |
struct iod_tuple{}; | |
template<class Head,class ...Tail> | |
struct iod_tuple<Head, Tail...>: Head,iod_tuple<Tail...> | |
{ | |
template<class H,class...T> | |
iod_tuple(H&&head,T&&...args) | |
:Head(std::forward<H>(head)),iod_tuple<Tail...>(std::forward<T>(args)...) | |
{} | |
}; | |
} | |
#define define_iod_name(NAME) \ | |
template<class T> \ | |
struct NAME##_type{ \ | |
template<class U>NAME##_type(U&&x) :NAME(std::forward<U>(x)){} \ | |
T NAME; \ | |
}; \ | |
template<class T> \ | |
using NAME = NAME##_type<T>; | |
define_iod_name(age) | |
define_iod_name(name) | |
define_iod_name(alive) | |
int main() | |
{ | |
iod::iod_tuple<age<int>, name<std::string>, alive<bool>> c{ 42, "Life", false }; | |
std::cout << c.age << c.name << c.alive; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment