1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
#include <string>
template < typename UType > struct X
{
X( UType type, double value, std::string type_name, std::string label )
: type(type), value(value), type_name( std::move(type_name) ), label( std::move(label) ) {}
UType type ;
double value ;
std::string type_name ;
std::string label ;
friend std::ostream& operator<< ( std::ostream& stm, const X& x )
{
return stm << "X{ " << x.type_name << '(' << (long long)x.type << "), "
<< x.value << ", " << x.label << " }" ;
}
};
int main()
{
enum distance { CMS, MTS, KMS };
const X diameter{ CMS, 12.6, "cms", "diameter" } ;
std::cout << diameter << '\n' ;
enum class storage : long long { KB = 1024, MB = KB*1024, GB = MB*1024, TB = GB*1024 };
const X disk_space { storage::GB, 1234.5, "GB", "disk space" } ;
std::cout << disk_space << '\n' ;
}
|