Created
November 22, 2010 04:30
-
-
Save hank/709520 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
all: | |
g++ -o test test.cpp |
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
hank@davros:~/tmp$ ./test | |
1 | |
Freeing Type! | |
5 | |
4.3 |
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> | |
#include <iostream> | |
#include <boost/fusion/sequence.hpp> | |
#include <boost/fusion/algorithm/iteration/for_each.hpp> | |
#include <boost/fusion/container/set.hpp> | |
#include <boost/fusion/include/sequence.hpp> | |
#include <boost/program_options.hpp> | |
#include <boost/fusion/include/filter_if.hpp> | |
using namespace std; | |
using namespace boost; | |
struct Type | |
{ | |
Type() | |
: attribute(1) | |
{} | |
~Type() | |
{ | |
printf("Freeing Type!\n"); fflush(stdout); | |
} | |
int attribute; | |
}; | |
ostream& operator<<(ostream& stream, Type t) | |
{ | |
stream << 1; | |
return stream; | |
} | |
struct print | |
{ | |
// This function works on pointers. | |
template<class E> | |
typename boost::disable_if_c<boost::is_pointer<E>::value, void>::type | |
operator()(E const x) const | |
{ | |
cout << x << endl; | |
} | |
// This function works on pointers. | |
template<class E> | |
typename boost::enable_if_c<boost::is_pointer<E>::value, void>::type | |
operator()(E const x) const | |
{ | |
cout << *(x) << endl; | |
} | |
}; | |
int main() | |
{ | |
typedef fusion::set<Type*, int, double> S; | |
Type* t = new Type; | |
S s(t, 5, 4.3); | |
fusion::for_each(s, print()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment