mirror of
https://github.com/boostorg/stl_interfaces.git
synced 2026-01-19 04:42:12 +00:00
Add test for entities in namespace detail.
This commit is contained in:
@@ -12,18 +12,8 @@
|
||||
namespace boost { namespace stl_interfaces {
|
||||
|
||||
namespace detail {
|
||||
template<typename T, typename = void>
|
||||
struct has_reserve : std::false_type
|
||||
{
|
||||
};
|
||||
template<typename T>
|
||||
struct has_reserve<T, void_t<decltype(std::declval<T &>().reserve())>>
|
||||
: std::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template<typename T, typename SizeType>
|
||||
struct n_iter : boost::stl_interfaces::iterator_interface<
|
||||
struct n_iter : iterator_interface<
|
||||
n_iter<T, SizeType>,
|
||||
std::random_access_iterator_tag,
|
||||
T>
|
||||
@@ -42,7 +32,7 @@ namespace boost { namespace stl_interfaces {
|
||||
}
|
||||
|
||||
private:
|
||||
friend boost::stl_interfaces::access;
|
||||
friend access;
|
||||
constexpr T const *& base_reference() noexcept { return x_; }
|
||||
constexpr T const * base_reference() const noexcept { return x_; }
|
||||
|
||||
@@ -54,7 +44,10 @@ namespace boost { namespace stl_interfaces {
|
||||
constexpr auto make_n_iter(T const & x, SizeType n) noexcept(
|
||||
noexcept(n_iter<T, SizeType>(x, n)))
|
||||
{
|
||||
return n_iter<T, SizeType>(x, SizeType(0));
|
||||
using result_type = n_iter<T, SizeType>;
|
||||
BOOST_STL_INTERFACES_STATIC_ASSERT_CONCEPT(
|
||||
result_type, std::random_access_iterator)
|
||||
return result_type(x, SizeType(0));
|
||||
}
|
||||
template<typename T, typename SizeType>
|
||||
constexpr auto make_n_iter_end(T const & x, SizeType n) noexcept(
|
||||
|
||||
@@ -55,11 +55,9 @@ namespace boost { namespace stl_interfaces {
|
||||
template<typename Range, typename = void>
|
||||
struct sentinel;
|
||||
template<typename Range>
|
||||
struct sentinel<
|
||||
Range,
|
||||
void_t<decltype(std::declval<Range &>().begin())>>
|
||||
struct sentinel<Range, void_t<decltype(std::declval<Range &>().end())>>
|
||||
{
|
||||
using type = decltype(std::declval<Range &>().begin());
|
||||
using type = decltype(std::declval<Range &>().end());
|
||||
};
|
||||
template<typename Range>
|
||||
using sentinel_t = typename sentinel<Range>::type;
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace boost { namespace stl_interfaces {
|
||||
|
||||
// TODO: Tests.
|
||||
// TODO: Look in all the headers for ADL traps.
|
||||
|
||||
/** This type is very similar to the C++20 version of
|
||||
@@ -19,7 +18,7 @@ namespace boost { namespace stl_interfaces {
|
||||
proxy-friendly. */
|
||||
template<typename BidiIter>
|
||||
struct reverse_iterator
|
||||
: boost::stl_interfaces::iterator_interface<
|
||||
: iterator_interface<
|
||||
reverse_iterator<BidiIter>,
|
||||
#if 201703L < __cplusplus && defined(__cpp_lib_ranges)
|
||||
typename std::iterator_traits<BidiIter>::iterator_concept,
|
||||
@@ -75,7 +74,7 @@ namespace boost { namespace stl_interfaces {
|
||||
}
|
||||
|
||||
private:
|
||||
friend boost::stl_interfaces::access;
|
||||
friend access;
|
||||
constexpr BidiIter & base_reference() noexcept { return it_; }
|
||||
constexpr BidiIter const & base_reference() const noexcept
|
||||
{
|
||||
|
||||
@@ -46,3 +46,4 @@ add_test_executable(forward)
|
||||
add_test_executable(bidirectional)
|
||||
add_test_executable(random_access)
|
||||
add_test_executable(reverse_iter)
|
||||
add_test_executable(detail)
|
||||
|
||||
82
test/detail.cpp
Normal file
82
test/detail.cpp
Normal file
@@ -0,0 +1,82 @@
|
||||
// Copyright (C) 2019 T. Zachary Laine
|
||||
//
|
||||
// Distributed under 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)
|
||||
#include <boost/stl_interfaces/iterator_interface.hpp>
|
||||
#include <boost/stl_interfaces/view_interface.hpp>
|
||||
#include <boost/stl_interfaces/container_interface.hpp>
|
||||
|
||||
#include <boost/mpl/assert.hpp>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace detail = boost::stl_interfaces::detail;
|
||||
|
||||
|
||||
// iter_difference_t
|
||||
BOOST_MPL_ASSERT(
|
||||
(std::is_same<detail::iter_difference_t<int *>, std::ptrdiff_t>));
|
||||
BOOST_MPL_ASSERT((std::is_same<
|
||||
detail::iter_difference_t<std::vector<double>::iterator>,
|
||||
std::vector<double>::difference_type>));
|
||||
BOOST_MPL_ASSERT((std::is_same<
|
||||
detail::iter_difference_t<std::list<double>::iterator>,
|
||||
std::list<double>::difference_type>));
|
||||
|
||||
struct ridiculous_range
|
||||
{
|
||||
int * begin() { return nullptr; }
|
||||
double end() { return 1.3; }
|
||||
};
|
||||
|
||||
// iterator_t
|
||||
BOOST_MPL_ASSERT((std::is_same<
|
||||
detail::iterator_t<std::vector<double>>,
|
||||
std::vector<double>::iterator>));
|
||||
BOOST_MPL_ASSERT((std::is_same<
|
||||
detail::iterator_t<std::list<double>>,
|
||||
std::list<double>::iterator>));
|
||||
BOOST_MPL_ASSERT((std::is_same<detail::iterator_t<ridiculous_range>, int *>));
|
||||
|
||||
// sentinel_t
|
||||
BOOST_MPL_ASSERT((std::is_same<
|
||||
detail::sentinel_t<std::vector<double>>,
|
||||
std::vector<double>::iterator>));
|
||||
BOOST_MPL_ASSERT((std::is_same<
|
||||
detail::sentinel_t<std::list<double>>,
|
||||
std::list<double>::iterator>));
|
||||
BOOST_MPL_ASSERT((std::is_same<detail::sentinel_t<ridiculous_range>, double>));
|
||||
|
||||
// range_difference_t
|
||||
BOOST_MPL_ASSERT(
|
||||
(std::is_same<
|
||||
detail::range_difference_t<std::vector<double>>,
|
||||
std::iterator_traits<std::vector<double>::iterator>::difference_type>));
|
||||
BOOST_MPL_ASSERT(
|
||||
(std::is_same<
|
||||
detail::range_difference_t<std::list<double>>,
|
||||
std::iterator_traits<std::list<double>::iterator>::difference_type>));
|
||||
BOOST_MPL_ASSERT((std::is_same<
|
||||
detail::range_difference_t<ridiculous_range>,
|
||||
std::ptrdiff_t>));
|
||||
|
||||
// common_range
|
||||
static_assert(detail::common_range<std::vector<double>>::value, "");
|
||||
static_assert(detail::common_range<std::list<double>>::value, "");
|
||||
static_assert(!detail::common_range<ridiculous_range>::value, "");
|
||||
|
||||
|
||||
TEST(detail, n_iter)
|
||||
{
|
||||
std::array<int, 5> ints = {{0, 1, 2, 3, 4}};
|
||||
int const new_value = 6;
|
||||
detail::n_iter<int, int> first = detail::make_n_iter(new_value, 3);
|
||||
detail::n_iter<int, int> last = detail::make_n_iter_end(new_value, 3);
|
||||
std::copy(first, last, &ints[1]);
|
||||
EXPECT_EQ(ints, (std::array<int, 5>{0, 6, 6, 6, 4}));
|
||||
}
|
||||
Reference in New Issue
Block a user