
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Lorenzo Caminiti Sent: Wednesday, July 18, 2012 6:13 AM To: boost@lists.boost.org; boost-announce@lists.boost.org; boost-users@lists.boost.org Subject: [boost] [type_erasure] Review started (July 18-27, 2012) *** The review of Steven Watanabe's proposed Boost.TypeErasure library begins on July 18, 2012 and ends on July 27, 2012. *** I'll post a fuller review in due course, but after playing with this I am tempted to cut to the chase and say YES. But here is an example that I have knocked up in a few minutes from print_sequence.cpp example (after a longer time struggling with the name TypeErasure and the concept in the docs). #include <libs/units/example/measurement.hpp> // An uncertain type called measure. int test[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; double testd[] = { 1., 2., 3., 4., 5., 6., 7., 8., 9., 10. }; quantity<length> testq[] = {2345.6 * meters, 123.4 * meters, 0.0123 * meters}; quantity<length, measurement<double> > testqu[] = {measurement<double>(45210.0, 1234.0) * meters, measurement<double>(789, 2.5) * meters, measurement<double>(0.000567,2.34e-5) * meters}; separator_printer p1(", "); // Construct a printer. p1.print(std::cout, test); // 1,2,3,4,5,6,7,8,9,10 std::cout << std::endl; separator_printer p1a("___"); // Construct a printer with underscore separator. p1a.print(std::cout, test); // 1___2___3___4___5___6___7___8___9___10 std::cout << std::endl; p1.print(std::cout, testd); // Type now double. std::cout << std::endl; // 1,2,3,4,5,6,7,8,9,10 std::cout.precision(5); // Make some fancy layout. std::cout << std::showpos << std::showpoint << std::endl; p1.print(std::cout, testd); // Type still double. std::cout << std::endl; // +1.0000,+2.0000,+3.0000,+4.0000,+5.0000,+6.0000,+7.0000,+8.0000,+9.0000,+10.000 std::cout << std::noshowpos << std::endl; // Switch off fancy +. p1.print(std::cout, testq); // Type now quantity of length. std::cout << std::endl; // 2.3456 km, 123.40 m, 12.300 mm // Note the cool change of unit prefix from km to m to mm! p1.print(std::cout, testqu); // Type now quantity of length with uncertainty estimate. std::cout << std::endl; // 45.210(+/-1.2340) km, 789.00(+/-2.5000) m, 567.00(+/-23.400) um // Note the cool change of unit prefix *and* showing uncertainty! I'm impressed ! Now if I can manage to string enough neurons together to write my own 'printers' etc, ... But already I sense this is a must-have bit of software. :-) Paul PS I can't come up with a better name than TypeErasure but it is certainly a bit forbidding :-(