#include "boost/variant.hpp"
boost::variant<int, std::string > f(int i)
{
if (i == 0)
{
return 1;
}
else
{
return std::string("str");
}
}
int main()
{
std::cout << f(0) << " " << f(1) << std::endl;
}
#include <iostream>
template <int I> struct i
{
enum { value = I };
};
double Func( i<1> P )
{
return 3.14159;
}
<code>
bool Func( i<2> P )
{
return false;
}
template <int I> std::string Func( i<I> P )
{
return "Something else";
}
int main()
{
std::cout << Func( i<1>() );
std::cout << std::endl;
std::cout << Func( i<2>() );
std::cout << std::endl;
std::cout << Func( i<3>() );
return 0;
}
class I {
// interface
// ...
virtual ~I() {}
};
class A: public I { ... }
class B: public I { ... }
I* foo(const int sw) {
return sw == 0 ? new A(...) : new B(...);
}