// Copyright (C) 2002 David A. Greene. All rights reserved. // // Named template parameter (NTP) testbench. #include "named_param.hh" #include "typelist.hh" #include #include // Define NTP tags and values (defaults listed first) // // Model - basic, limited_edition // Color - black, white // Seats - no_leather, leather // Transmission - automatic, manual class model_tag {}; class basic {}; class limited_edition {}; class color_tag {}; class black {}; class white {}; class seats_tag {}; class no_leather {}; class leather {}; class transmission_tag {}; class automatic {}; class manual {}; // Typelist NTP - Pass the config as a single typelist of NTPs. template::type> class car_as_typelist { private: // The user-provided parameter tag/type map. typedef Config config_typelist; // Find the pair corresponding to the model and extract // the given type, or the default (basic) if it is not there. typedef typename mpl::extract_named_param_or_default:: template apply::result model_type; // Ditto for the color. typedef typename mpl::extract_named_param_or_default:: template apply::result color_type; // Seats typedef typename mpl::extract_named_param_or_default:: template apply::result seats_type; // Tranny typedef typename mpl::extract_named_param_or_default:: template apply::result transmission_type; public: car_as_typelist(void) { std::cout << typeid(*this).name() << std::endl; std::cout << "Model: " << typeid(model_type).name() << std::endl; std::cout << "Color: " << typeid(color_type).name() << std::endl; std::cout << "Seats: " << typeid(seats_type).name() << std::endl; std::cout << "Transmission: " << typeid(transmission_type).name() << std::endl; }; }; // Scalar NTP. Right now this assumes everything is a NTP. We can // use the same trick as in the Boost NTP sandbox to distinguish // NTP and non-NTP arguments and provide appropriate defaults here. template class car_as_scalar : public car_as_typelist::type> {}; void typelist_test(void) { std::cout << "typelist_test" << std::endl; // Try all defaults car_as_typelist<> default_car; // Set the model and tranny typedef mpl::make_typelist_2, mpl::ntp >::type limited_manual_config; car_as_typelist limited_manual_car; // Set the color and seats typedef mpl::make_typelist_2, mpl::ntp >::type white_leather_config; car_as_typelist white_leather_car; } void scalar_test(void) { std::cout << "scalar_test" << std::endl; // Try all defaults car_as_scalar<> default_car; // Set the model and tranny car_as_scalar, mpl::ntp > limited_manual_car; // Set the color and seats car_as_scalar, mpl::ntp > white_leather_car; } int main(void) { typelist_test(); scalar_test(); return(0); }