#include <boost/any.hpp>
#include <iostream>

class number {
	boost::any data;
public:

	number(int d) : data(d) {}
	number(double d) : data(d) {}

	bool is_int() const { return data.type() == typeid(int); }
	bool is_double() const { return data.type() == typeid(double); }

	int as_int() const { return boost::any_cast<int>(data); }
	double as_double() const { return boost::any_cast<double>(data); }

	void operator+=(number const & other)
	{
		if (is_int()) {
			if (other.is_int()) {
				data = as_int() + other.as_int();
			} else {
				data = as_int() + other.as_double();
			}
		} else {
			if (other.is_int()) {
				data = as_double() + other.as_int();
			} else {
				data = as_double() + other.as_double();
			}
		}
	}
};

number operator+(number const & lhs, number const & rhs)
{
	number tmp = lhs;
	tmp += rhs;
	return tmp;
}


void print(char const * name, number const & data)
{
	std::cout << name << " has type "
		  << (data.is_int() ? "int" : "double")
		  << " and value "
		  << (data.is_int() ? data.as_int() : data.as_double())
		  << std::endl;
}


int main()
{
	number const value1(double(127));
	number const value2(int(17));
	number const value3 = value1 + value2;

	print("value1", value1);
	print("value2", value2);
	print("value3", value3);

	return 0;
}
