Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
runtime template mode processor
//g++ 5.4.0 #include <iostream> #include <boost/algorithm/string.hpp> #include <boost/program_options.hpp> namespace po = boost::program_options; template<int N> class Processor{ public: std::string operator()(std::string&& s) const { return Processor<N & (N-1)>()(Processor<N & ~(N-1)>()(s)); } }; template<> class Processor<0>{ public: std::string operator()(std::string&& s) const { return s; } }; enum Modes { md_tolower = 1, md_toupper = 2, md_capitalize = 4, md_trim_start = 8, md_trim_end = 16, md_normalize_spaces = 32, md_stem = 64, md_sort = 128, }; template<> class Processor<md_tolower>{ public: std::string operator()(std::string&& s) const { boost::to_lower(s); return s; } }; template<> class Processor<md_toupper>{ public: std::string operator()(std::string&& s) const { boost::to_upper(s); return s; } }; template<> class Processor<md_capitalize>{ public: std::string operator()(std::string&& s) const { return s; } }; template<> class Processor<md_trim_start>{ public: std::string operator()(std::string&& s) const { return s; // STUB } }; template<> class Processor<md_trim_end>{ public: std::string operator()(std::string&& s) const { return s; // STUB } }; template<> class Processor<md_normalize_spaces>{ public: std::string operator()(std::string&& s) const { return s; // STUB } }; template<> class Processor<md_stem>{ public: std::string operator()(std::string&& s) const { return s; // STUB } }; template<> class Processor<md_sort>{ public: std::string operator()(std::string&& s) const { return s; // STUB } }; std::string apply(int mode, std::string&& value){ // TODO return value; } int main(int argc, char** argv) { int mode = 0; std::string value; po::options_description config_option_list("config options"); config_option_list.add_options() ("mode", po::value<int>(&mode)->default_value(0), "") ("value", po::value<std::string>(&value)->default_value(""), "") ; po::options_description option_list; option_list.add(config_option_list); po::command_line_parser parser(argc, argv); parser.options(option_list); po::variables_map option_values; po::store(parser.run(), option_values); po::notify(option_values); std::cout << apply(mode, std::move(value)) << std::endl; }
run
|
edit
|
history
|
help
0
Building squares using smallest amount of matches
How to make stupid to my friend?
fibonacci
vector destruction - gcc
Testing C++
BridgeEdge
shared_ptr deleter
Best time to buy and sell stocks
ShoppingList
string_match