Created
January 2, 2013 15:09
-
-
Save robertmaynard/4435237 to your computer and use it in GitHub Desktop.
simple example of a fusion style rtim of a tuple.
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
namespace detail | |
{ | |
//create a Factory item with only the first N items in it | |
template< template<class ...> class Factory, | |
int TruncateSize, | |
int ItemsToDrop, | |
class T, | |
class ...OtherArgs> | |
struct rtrim | |
{ | |
typedef typename rtrim<Factory,TruncateSize,ItemsToDrop-1,OtherArgs...,T>::type type; | |
type operator()(T t, OtherArgs... args) const | |
{ | |
return rtrim<Factory,TruncateSize,ItemsToDrop-1,OtherArgs...,T>()(args...,t); | |
} | |
}; | |
//create a Factory item with only the first N items in it | |
template<template<class ...> class Factory, int TruncateSize, class T, class ...OtherArgs> | |
struct rtrim<Factory, TruncateSize, 0, T, OtherArgs...> | |
{ | |
enum{M = sizeof...(OtherArgs) - TruncateSize}; | |
typedef typename ltrim<Factory,M,OtherArgs...,T>::type type; | |
type operator()(T t, OtherArgs... args) const | |
{ | |
return ltrim<Factory,M,OtherArgs...,T>()(args...,t); | |
} | |
}; | |
} | |
//create a Factory item with only the first N items in it, aka rtrim | |
template< template<class ...> class Factory, | |
int TruncateSize, | |
class T, | |
class ...OtherArgs> | |
struct rtrim | |
{ | |
typedef typename detail::rtrim<Factory,TruncateSize,TruncateSize-1,OtherArgs...,T>::type type; | |
type operator()(T t, OtherArgs... args) const | |
{ | |
return detail::rtrim<Factory,TruncateSize,TruncateSize-1,OtherArgs...,T>()(args...,t); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment