/// \file // Range v3 library // // Copyright Andrey Diduh 2019 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #include #include #include #include #include #include #include #include "../simple_test.hpp" #include "../test_utils.hpp" using namespace ranges; void simple_test() { std::vector list = {1,2,3}; auto out = list | views::addressof; check_equal(out, {&list[0], &list[1], &list[2]}); } struct test_istream_range : view_facade { private: friend range_access; std::vector *list; struct cursor { private: std::size_t i = 0; std::vector *list = nullptr; public: cursor() = default; explicit cursor(std::vector &list_) : list(&list_) {} void next() { ++i; } int &read() const noexcept { return (*list)[i]; } bool equal(default_sentinel_t) const { return i == list->size(); } }; cursor begin_cursor() { return cursor{*list}; } public: test_istream_range() = default; explicit test_istream_range(std::vector &list_) : list(&list_) {} }; void test_input_range() { // It is implementation dependent, // for how long returned reference remains valid. // It should be valid at least until next read. // For test purposes we use custom input range. std::vector list{1, 2, 3}; auto rng = test_istream_range(list); CPP_assert(input_range); auto out = rng | views::addressof; check_equal(out, {&list[0], &list[1], &list[2]}); } struct test_xvalue_range : view_facade { private: friend range_access; struct cursor { cursor() = default; void next(); int &&read() const noexcept; bool equal(default_sentinel_t) const; }; cursor begin_cursor(); }; template constexpr bool can_view = false; template constexpr bool can_view()))>> = true; // prvalue ranges cannot be passed to views::addressof CPP_assert(!can_view); // xvalue ranges cannot be passed to views::addressof CPP_assert(!can_view); int main() { simple_test(); test_input_range(); return test_result(); }