Skip to content

Commit

Permalink
refs #139 burst::to_forward_list
Browse files Browse the repository at this point in the history
  • Loading branch information
izvolov committed Oct 25, 2020
1 parent 0103a4d commit 8022c39
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
40 changes: 40 additions & 0 deletions include/burst/range/adaptor/to_forward_list.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef BURST_RANGE_ADAPTOR_TO_FORWARD_LIST_HPP
#define BURST_RANGE_ADAPTOR_TO_FORWARD_LIST_HPP

#include <burst/range/adaptor/adaptor.hpp>
#include <burst/container/make_forward_list.hpp>

namespace burst
{
struct make_forward_list_t
{
template <typename... Xs>
constexpr auto operator () (Xs &&... xs) const
{
return make_forward_list(std::forward<Xs>(xs)...);
}
};

/*!
\brief
Инструмент для конструирования односвязного списка через конвейер
\details
Вызов
\code{.cpp}
range | to_forward_list
\endcode
эквивалентен вызову
\code{.cpp}
make_forward_list(range)
\endcode
\see make_forward_list
*/
constexpr auto to_forward_list = make_adaptor_trigger(make_forward_list_t{});
} // namespace burst

#endif // BURST_RANGE_ADAPTOR_TO_FORWARD_LIST_HPP
1 change: 1 addition & 0 deletions test/burst/range/adaptor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ target_sources(burst-unit-tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/taken_at_most.cpp
${CMAKE_CURRENT_SOURCE_DIR}/taken_exactly.cpp
${CMAKE_CURRENT_SOURCE_DIR}/to_deque.cpp
${CMAKE_CURRENT_SOURCE_DIR}/to_forward_list.cpp
${CMAKE_CURRENT_SOURCE_DIR}/to_list.cpp
${CMAKE_CURRENT_SOURCE_DIR}/to_vector.cpp
${CMAKE_CURRENT_SOURCE_DIR}/united.cpp
Expand Down
33 changes: 33 additions & 0 deletions test/burst/range/adaptor/to_forward_list.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <burst/range/adaptor/to_forward_list.hpp>

#include <doctest/doctest.h>

#include <boost/range/irange.hpp>

#include <forward_list>
#include <initializer_list>
#include <list>

TEST_SUITE("to_forward_list")
{
TEST_CASE("Может работать с rvalue-диапазоном")
{
const auto fl = boost::irange<int>(0, 10) | burst::to_forward_list;
CHECK(fl == std::forward_list<int>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
}

TEST_CASE("Может работать с lvalue-диапазоном")
{
const auto l = std::list<char>{'a', 'b', 'c'};

const auto fl = l | burst::to_forward_list;
CHECK(fl == std::forward_list<char>{'a', 'b', 'c'});
}

TEST_CASE("Может работать со списком инициализации")
{
const auto il = std::initializer_list<char>{'a', 'b', 'c'};
const auto fl = il | burst::to_forward_list;
CHECK(fl == std::forward_list<char>{'a', 'b', 'c'});
}
}

0 comments on commit 8022c39

Please sign in to comment.