//******************************************************** // 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 int main() { std::vector data{47, 11, 42, 0, 8, 15}; std::vector v1{data.begin(), data.end()}; std::println("v1: {}", v1); // OK std::vector v2{data.begin(), data.end()}; std::println("v2: {}", v2); // ERROR: elements are iterators std::vector v3(data.begin(), data.end()); // OK (note: parentheses) std::println("v3: {}", v3); std::vector v4{std::from_range, data}; // OK std::println("v4: {}", v4); auto vPrimes = std::views::iota(1, 100) // values from 1 to 99 | std::views::filter(isPrime) // only prime numbers | std::views::take(10); // at most 10 std::vector v5{vPrimes.begin(), vPrimes.end()}; // ERROR: no common range std::vector v6{std::from_range, vPrimes}; // OK std::println("v6: {}", v6); }