//******************************************************** // The following code example is taken from the book // C++23 - The Complete Guide // by Nicolai M. Josuttis (www.josuttis.com) // http://www.cppstd23.com // // The code is licensed under a // Creative Commons Attribution 4.0 International License // http://creativecommons.org/licenses/by/4.0/ //******************************************************** #include #include #include #include #include void printValueRange(auto&& rg) { std::println(" default: {}", rg); std::println(" {{::}} : {::}", rg); std::println(" {{:n}} : {:n}", rg); std::println(" {{:n:}} : {:n:}", rg); } int main() { // ranges of values: std::println("vector:"); printValueRange(std::vector{"tic", "tac", "toe"}); std::println("\nset:"); printValueRange(std::set{"tic", "tac", "toe"}); std::println("\nRaw array of strings:"); std::string arr[] = {"tic", "tac", "toe"}; printValueRange(arr); std::println("\nView on set:"); printValueRange(std::set{"tic", "tac", "toe"} | std::views::all); // ranges of chars: std::println("\nvector:"); std::println(" default: {}", std::vector{'a', '\t', 'b'}); std::println(" {{::?}} : {::?}", std::vector{'a', '\t', 'b'}); std::println(" {{::}} : {::}", std::vector{'a', '\t', 'b'}); std::println(" {{:s}} : {:s}", std::vector{'a', '\t', 'b'}); }