Created
September 7, 2010 16:43
-
-
Save niha/568644 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 <cstdio> | |
template <typename... seq> | |
struct array; | |
template <typename ary> | |
struct head; | |
template <typename first, typename... rest> | |
struct head<array<first, rest...>> { | |
typedef first type; | |
}; | |
template <typename lhs, typename rhs> | |
struct append; | |
template <typename... lhs, typename... rhs> | |
struct append<array<lhs...>, array<rhs...>> { | |
typedef array<lhs..., rhs...> type; | |
}; | |
template <typename ary, int n> | |
struct split_at; | |
template <typename ary> | |
struct split_at<ary, 0> { | |
typedef array<> front; | |
typedef ary back; | |
}; | |
template <typename head, typename... tail> | |
struct split_at<array<head, tail...>, 1> { | |
typedef array<head> front; | |
typedef array<tail...> back; | |
}; | |
template <typename... seq, int n> | |
struct split_at<array<seq...>, n> { | |
static const int lhs_len = n / 2; | |
static const int rhs_len = n - lhs_len; | |
typedef split_at<array<seq...>, lhs_len> lhs; | |
typedef typename lhs::front lhs_front; | |
typedef typename lhs::back lhs_back; | |
typedef split_at<lhs_back, rhs_len> rhs; | |
typedef typename rhs::front rhs_front; | |
typedef typename rhs::back rhs_back; | |
typedef typename append<lhs_front, rhs_front>::type front; | |
typedef rhs_back back; | |
}; | |
template <typename T, int size> | |
struct fill; | |
template <typename T> | |
struct fill<T, 0> { | |
typedef array<> type; | |
}; | |
template <typename T> | |
struct fill<T, 1> { | |
typedef array<T> type; | |
}; | |
template <typename T, int size> | |
struct fill { | |
static const int lhs_size = size / 2; | |
static const int rhs_size = size - lhs_size; | |
typedef typename fill<T, lhs_size>::type lhs; | |
typedef typename fill<T, rhs_size>::type rhs; | |
typedef typename append<lhs, rhs>::type type; | |
}; | |
typedef | |
typename fill<int, 1024>::type | |
tmp; | |
typedef | |
typename append<tmp, array<double>>::type | |
tmp_; | |
typedef | |
typename split_at<tm_, 1024>::back | |
tmp__; | |
typedef | |
typename head<tmp__>::type | |
should_double; | |
int main(){ | |
should_double d = 1.0; | |
printf("%lf\n", d); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment