Skip to content

Instantly share code, notes, and snippets.

@hank
Created November 22, 2010 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hank/709520 to your computer and use it in GitHub Desktop.
Save hank/709520 to your computer and use it in GitHub Desktop.
all:
g++ -o test test.cpp
hank@davros:~/tmp$ ./test
1
Freeing Type!
5
4.3
#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