Created
August 6, 2015 17:33
-
-
Save bennofs/26350a70da265e378cd3 to your computer and use it in GitHub Desktop.
Extract template from type
This file contains hidden or 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
| 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