Skip to content

Instantly share code, notes, and snippets.

@bennofs
Created August 6, 2015 17:33
Show Gist options
  • Select an option

  • Save bennofs/26350a70da265e378cd3 to your computer and use it in GitHub Desktop.

Select an option

Save bennofs/26350a70da265e378cd3 to your computer and use it in GitHub Desktop.
Extract template from type
struct SampleData {
Container<float> totalradiance;
Container<int> lightcutSize;
template <class T>
struct decl_sampledata_from_container {};
template <template <class, class...> class C, class T>
struct decl_sampledata_from_container<C<T>> {
typedef SampleData<C> type;
};
template <class Fun>
auto make(Fun make)
-> typename decl_sampledata_from_container<decltype(make(totalradiance))>::type
{
return {
make(totalradiance )
, make(lightcutSize )
};
}
};
struct converter
{
template <class T>
::std::list<T> operator()(::std::vector<T>& v)
{
return ::std::list<T>(v.begin(), v.end());
}
};
int main() {
SampleData<::std::vector> samples;
SampleData<::std::list> const converted = samples.make(converter());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment