Merge pull request #32 from BlackMATov/dev

Dev
This commit is contained in:
2020-11-30 05:26:22 +07:00
committed by GitHub
18 changed files with 7143 additions and 156 deletions

View File

@@ -1,4 +0,0 @@
ignore:
- "catch.hpp"
- "catch_main.hpp"
- "*_tests.cpp"

View File

@@ -1,32 +1,12 @@
git:
depth: false
quiet: true
language: cpp
matrix:
jobs:
include:
#
# windows (MSVC 2017)
#
- os: windows
stage: windows
name: debug, MSVC 2017, x86
script: ./scripts/build_debug_x86.bat
- os: windows
stage: windows
name: release, MSVC 2017, x86
script: ./scripts/build_release_x86.bat
- os: windows
stage: windows
name: debug, MSVC 2017, x64
script: ./scripts/build_debug_x64.bat
- os: windows
stage: windows
name: release, MSVC 2017, x64
script: ./scripts/build_release_x64.bat
#
# linux (g++-7)
#
@@ -75,7 +55,7 @@ matrix:
dist: xenial
stage: linux
name: debug, clang++-5.0
addons: { apt: { sources: ["ubuntu-toolchain-r-test", "llvm-toolchain-xenial-5.0"], packages: ["g++-7", "clang-5.0"] } }
addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-7", "clang-5.0"] } }
env: CC=clang-5.0 CXX=clang++-5.0
script: ./scripts/build_debug.sh
@@ -83,7 +63,7 @@ matrix:
dist: xenial
stage: linux
name: release, clang++-5.0
addons: { apt: { sources: ["ubuntu-toolchain-r-test", "llvm-toolchain-xenial-5.0"], packages: ["g++-7", "clang-5.0"] } }
addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-7", "clang-5.0"] } }
env: CC=clang-5.0 CXX=clang++-5.0
script: ./scripts/build_release.sh
@@ -95,7 +75,7 @@ matrix:
dist: xenial
stage: linux
name: debug, clang++-6.0
addons: { apt: { sources: ["ubuntu-toolchain-r-test", "llvm-toolchain-xenial-6.0"], packages: ["g++-7", "clang-6.0"] } }
addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-7", "clang-6.0"] } }
env: CC=clang-6.0 CXX=clang++-6.0
script: ./scripts/build_debug.sh
@@ -103,7 +83,7 @@ matrix:
dist: xenial
stage: linux
name: release, clang++-6.0
addons: { apt: { sources: ["ubuntu-toolchain-r-test", "llvm-toolchain-xenial-6.0"], packages: ["g++-7", "clang-6.0"] } }
addons: { apt: { sources: ["ubuntu-toolchain-r-test"], packages: ["g++-7", "clang-6.0"] } }
env: CC=clang-6.0 CXX=clang++-6.0
script: ./scripts/build_release.sh
@@ -149,11 +129,3 @@ matrix:
name: coverage, xcode10
addons: { homebrew: { packages: ["lcov"], update: true } }
script: ./scripts/upload_coverage.sh
before_install:
- if [ "$TRAVIS_OS_NAME" == 'linux' ]; then
mkdir $HOME/cmake;
export PATH="$HOME/cmake/bin:$PATH";
travis_retry wget -q https://cmake.org/files/v3.11/cmake-3.11.4-Linux-x86_64.sh;
sh cmake-3.11.4-Linux-x86_64.sh --prefix=$HOME/cmake --exclude-subdir --skip-license;
fi

View File

@@ -0,0 +1,24 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/flat.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2019-2020, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
#include <type_traits>
#include <utility>
namespace flat_hpp::detail
{
template < typename Allocator, typename = void >
struct is_allocator : std::false_type {};
template < typename Allocator >
struct is_allocator<Allocator, std::void_t<
typename Allocator::value_type,
decltype(std::declval<Allocator&>().deallocate(
std::declval<Allocator&>().allocate(std::size_t{1}),
std::size_t{1}))
>> : std::true_type {};
}

View File

@@ -0,0 +1,22 @@
/*******************************************************************************
* This file is part of the "https://github.com/blackmatov/flat.hpp"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2019-2020, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
#include <iterator>
#include <type_traits>
namespace flat_hpp::detail
{
template < typename InputIter >
using iter_value_type = typename std::iterator_traits<InputIter>::value_type;
template < typename InputIter >
using iter_key_type = std::remove_const_t<typename iter_value_type<InputIter>::first_type>;
template < typename InputIter >
using iter_mapped_type = typename iter_value_type<InputIter>::second_type;
}

View File

@@ -6,18 +6,21 @@
#pragma once
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <cassert>
#include <functional>
#include <type_traits>
#include <initializer_list>
#include <stdexcept>
#include <type_traits>
#include <utility>
#include <vector>
#include "detail/is_sorted.hpp"
#include "detail/eq_compare.hpp"
#include "detail/pair_compare.hpp"
#include "detail/is_allocator.hpp"
#include "detail/is_sorted.hpp"
#include "detail/is_transparent.hpp"
#include "detail/iter_traits.hpp"
#include "detail/pair_compare.hpp"
namespace flat_hpp
{

View File

@@ -709,6 +709,102 @@ namespace flat_hpp
};
}
namespace flat_hpp
{
template < typename InputIter, typename Allocator
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_map(InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_map<detail::iter_key_type<InputIter>, detail::iter_mapped_type<InputIter>>;
template < typename InputIter, typename Allocator
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_map(sorted_range_t, InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_map<detail::iter_key_type<InputIter>, detail::iter_mapped_type<InputIter>>;
template < typename InputIter, typename Allocator
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_map(sorted_unique_range_t, InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_map<detail::iter_key_type<InputIter>, detail::iter_mapped_type<InputIter>>;
//
template < typename InputIter
, typename Compare = std::less<detail::iter_key_type<InputIter>>
, typename Allocator = std::allocator<std::pair<
std::add_const_t<detail::iter_key_type<InputIter>>,
detail::iter_mapped_type<InputIter>>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_map(InputIter, InputIter, Compare = Compare(), Allocator = Allocator())
-> flat_map<detail::iter_key_type<InputIter>, detail::iter_mapped_type<InputIter>, Compare>;
template < typename InputIter
, typename Compare = std::less<detail::iter_key_type<InputIter>>
, typename Allocator = std::allocator<std::pair<
std::add_const_t<detail::iter_key_type<InputIter>>,
detail::iter_mapped_type<InputIter>>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_map(sorted_range_t, InputIter, InputIter, Compare = Compare(), Allocator = Allocator())
-> flat_map<detail::iter_key_type<InputIter>, detail::iter_mapped_type<InputIter>, Compare>;
template < typename InputIter
, typename Compare = std::less<detail::iter_key_type<InputIter>>
, typename Allocator = std::allocator<std::pair<
std::add_const_t<detail::iter_key_type<InputIter>>,
detail::iter_mapped_type<InputIter>>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_map(sorted_unique_range_t, InputIter, InputIter, Compare = Compare(), Allocator = Allocator())
-> flat_map<detail::iter_key_type<InputIter>, detail::iter_mapped_type<InputIter>, Compare>;
//
template < typename Key, typename Value
, typename Allocator = std::allocator<std::pair<const Key, Value>>
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_map(std::initializer_list<std::pair<Key, Value>>, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_map<std::remove_const_t<Key>, Value>;
template < typename Key, typename Value
, typename Allocator = std::allocator<std::pair<const Key, Value>>
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_map(sorted_range_t, std::initializer_list<std::pair<Key, Value>>, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_map<std::remove_const_t<Key>, Value>;
template < typename Key, typename Value
, typename Allocator = std::allocator<std::pair<const Key, Value>>
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_map(sorted_unique_range_t, std::initializer_list<std::pair<Key, Value>>, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_map<std::remove_const_t<Key>, Value>;
//
template < typename Key, typename Value
, typename Compare = std::less<std::remove_const_t<Key>>
, typename Allocator = std::allocator<std::pair<const Key, Value>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_map(std::initializer_list<std::pair<Key, Value>>, Compare = Compare(), Allocator = Allocator())
-> flat_map<std::remove_const_t<Key>, Value, Compare>;
template < typename Key, typename Value
, typename Compare = std::less<std::remove_const_t<Key>>
, typename Allocator = std::allocator<std::pair<const Key, Value>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_map(sorted_range_t, std::initializer_list<std::pair<Key, Value>>, Compare = Compare(), Allocator = Allocator())
-> flat_map<std::remove_const_t<Key>, Value, Compare>;
template < typename Key, typename Value
, typename Compare = std::less<std::remove_const_t<Key>>
, typename Allocator = std::allocator<std::pair<const Key, Value>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_map(sorted_unique_range_t, std::initializer_list<std::pair<Key, Value>>, Compare = Compare(), Allocator = Allocator())
-> flat_map<std::remove_const_t<Key>, Value, Compare>;
}
namespace flat_hpp
{
template < typename Key

View File

@@ -594,6 +594,102 @@ namespace flat_hpp
};
}
namespace flat_hpp
{
template < typename InputIter, typename Allocator
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multimap(InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_multimap<detail::iter_key_type<InputIter>, detail::iter_mapped_type<InputIter>>;
template < typename InputIter, typename Allocator
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multimap(sorted_range_t, InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_multimap<detail::iter_key_type<InputIter>, detail::iter_mapped_type<InputIter>>;
template < typename InputIter, typename Allocator
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multimap(sorted_unique_range_t, InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_multimap<detail::iter_key_type<InputIter>, detail::iter_mapped_type<InputIter>>;
//
template < typename InputIter
, typename Compare = std::less<detail::iter_key_type<InputIter>>
, typename Allocator = std::allocator<std::pair<
std::add_const_t<detail::iter_key_type<InputIter>>,
detail::iter_mapped_type<InputIter>>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multimap(InputIter, InputIter, Compare = Compare(), Allocator = Allocator())
-> flat_multimap<detail::iter_key_type<InputIter>, detail::iter_mapped_type<InputIter>, Compare>;
template < typename InputIter
, typename Compare = std::less<detail::iter_key_type<InputIter>>
, typename Allocator = std::allocator<std::pair<
std::add_const_t<detail::iter_key_type<InputIter>>,
detail::iter_mapped_type<InputIter>>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multimap(sorted_range_t, InputIter, InputIter, Compare = Compare(), Allocator = Allocator())
-> flat_multimap<detail::iter_key_type<InputIter>, detail::iter_mapped_type<InputIter>, Compare>;
template < typename InputIter
, typename Compare = std::less<detail::iter_key_type<InputIter>>
, typename Allocator = std::allocator<std::pair<
std::add_const_t<detail::iter_key_type<InputIter>>,
detail::iter_mapped_type<InputIter>>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multimap(sorted_unique_range_t, InputIter, InputIter, Compare = Compare(), Allocator = Allocator())
-> flat_multimap<detail::iter_key_type<InputIter>, detail::iter_mapped_type<InputIter>, Compare>;
//
template < typename Key, typename Value
, typename Allocator = std::allocator<std::pair<const Key, Value>>
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multimap(std::initializer_list<std::pair<Key, Value>>, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_multimap<std::remove_const_t<Key>, Value>;
template < typename Key, typename Value
, typename Allocator = std::allocator<std::pair<const Key, Value>>
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multimap(sorted_range_t, std::initializer_list<std::pair<Key, Value>>, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_multimap<std::remove_const_t<Key>, Value>;
template < typename Key, typename Value
, typename Allocator = std::allocator<std::pair<const Key, Value>>
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multimap(sorted_unique_range_t, std::initializer_list<std::pair<Key, Value>>, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_multimap<std::remove_const_t<Key>, Value>;
//
template < typename Key, typename Value
, typename Compare = std::less<std::remove_const_t<Key>>
, typename Allocator = std::allocator<std::pair<const Key, Value>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multimap(std::initializer_list<std::pair<Key, Value>>, Compare = Compare(), Allocator = Allocator())
-> flat_multimap<std::remove_const_t<Key>, Value, Compare>;
template < typename Key, typename Value
, typename Compare = std::less<std::remove_const_t<Key>>
, typename Allocator = std::allocator<std::pair<const Key, Value>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multimap(sorted_range_t, std::initializer_list<std::pair<Key, Value>>, Compare = Compare(), Allocator = Allocator())
-> flat_multimap<std::remove_const_t<Key>, Value, Compare>;
template < typename Key, typename Value
, typename Compare = std::less<std::remove_const_t<Key>>
, typename Allocator = std::allocator<std::pair<const Key, Value>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multimap(sorted_unique_range_t, std::initializer_list<std::pair<Key, Value>>, Compare = Compare(), Allocator = Allocator())
-> flat_multimap<std::remove_const_t<Key>, Value, Compare>;
}
namespace flat_hpp
{
template < typename Key

View File

@@ -510,6 +510,96 @@ namespace flat_hpp
};
}
namespace flat_hpp
{
template < typename InputIter, typename Allocator
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multiset(InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_multiset<detail::iter_value_type<InputIter>>;
template < typename InputIter, typename Allocator
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multiset(sorted_range_t, InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_multiset<detail::iter_value_type<InputIter>>;
template < typename InputIter, typename Allocator
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multiset(sorted_unique_range_t, InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_multiset<detail::iter_value_type<InputIter>>;
//
template < typename InputIter
, typename Compare = std::less<detail::iter_value_type<InputIter>>
, typename Allocator = std::allocator<detail::iter_value_type<InputIter>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multiset(InputIter, InputIter, Compare = Compare(), Allocator = Allocator())
-> flat_multiset<detail::iter_value_type<InputIter>, Compare>;
template < typename InputIter
, typename Compare = std::less<detail::iter_value_type<InputIter>>
, typename Allocator = std::allocator<detail::iter_value_type<InputIter>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multiset(sorted_range_t, InputIter, InputIter, Compare = Compare(), Allocator = Allocator())
-> flat_multiset<detail::iter_value_type<InputIter>, Compare>;
template < typename InputIter
, typename Compare = std::less<detail::iter_value_type<InputIter>>
, typename Allocator = std::allocator<detail::iter_value_type<InputIter>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multiset(sorted_unique_range_t, InputIter, InputIter, Compare = Compare(), Allocator = Allocator())
-> flat_multiset<detail::iter_value_type<InputIter>, Compare>;
//
template < typename Key
, typename Allocator = std::allocator<Key>
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multiset(std::initializer_list<Key>, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_multiset<Key>;
template < typename Key
, typename Allocator = std::allocator<Key>
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multiset(sorted_range_t, std::initializer_list<Key>, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_multiset<Key>;
template < typename Key
, typename Allocator = std::allocator<Key>
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multiset(sorted_unique_range_t, std::initializer_list<Key>, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_multiset<Key>;
//
template < typename Key
, typename Compare = std::less<Key>
, typename Allocator = std::allocator<Key>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multiset(std::initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
-> flat_multiset<Key, Compare>;
template < typename Key
, typename Compare = std::less<Key>
, typename Allocator = std::allocator<Key>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multiset(sorted_range_t, std::initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
-> flat_multiset<Key, Compare>;
template < typename Key
, typename Compare = std::less<Key>
, typename Allocator = std::allocator<Key>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_multiset(sorted_unique_range_t, std::initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
-> flat_multiset<Key, Compare>;
}
namespace flat_hpp
{
template < typename Key

View File

@@ -583,6 +583,96 @@ namespace flat_hpp
};
}
namespace flat_hpp
{
template < typename InputIter, typename Allocator
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_set(InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_set<detail::iter_value_type<InputIter>>;
template < typename InputIter, typename Allocator
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_set(sorted_range_t, InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_set<detail::iter_value_type<InputIter>>;
template < typename InputIter, typename Allocator
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_set(sorted_unique_range_t, InputIter, InputIter, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_set<detail::iter_value_type<InputIter>>;
//
template < typename InputIter
, typename Compare = std::less<detail::iter_value_type<InputIter>>
, typename Allocator = std::allocator<detail::iter_value_type<InputIter>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_set(InputIter, InputIter, Compare = Compare(), Allocator = Allocator())
-> flat_set<detail::iter_value_type<InputIter>, Compare>;
template < typename InputIter
, typename Compare = std::less<detail::iter_value_type<InputIter>>
, typename Allocator = std::allocator<detail::iter_value_type<InputIter>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_set(sorted_range_t, InputIter, InputIter, Compare = Compare(), Allocator = Allocator())
-> flat_set<detail::iter_value_type<InputIter>, Compare>;
template < typename InputIter
, typename Compare = std::less<detail::iter_value_type<InputIter>>
, typename Allocator = std::allocator<detail::iter_value_type<InputIter>>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_set(sorted_unique_range_t, InputIter, InputIter, Compare = Compare(), Allocator = Allocator())
-> flat_set<detail::iter_value_type<InputIter>, Compare>;
//
template < typename Key
, typename Allocator = std::allocator<Key>
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_set(std::initializer_list<Key>, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_set<Key>;
template < typename Key
, typename Allocator = std::allocator<Key>
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_set(sorted_range_t, std::initializer_list<Key>, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_set<Key>;
template < typename Key
, typename Allocator = std::allocator<Key>
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_set(sorted_unique_range_t, std::initializer_list<Key>, Allocator, int* msvc_2017_workaround = nullptr)
-> flat_set<Key>;
//
template < typename Key
, typename Compare = std::less<Key>
, typename Allocator = std::allocator<Key>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_set(std::initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
-> flat_set<Key, Compare>;
template < typename Key
, typename Compare = std::less<Key>
, typename Allocator = std::allocator<Key>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_set(sorted_range_t, std::initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
-> flat_set<Key, Compare>;
template < typename Key
, typename Compare = std::less<Key>
, typename Allocator = std::allocator<Key>
, std::enable_if_t<!detail::is_allocator<Compare>::value, int> = 0
, std::enable_if_t<detail::is_allocator<Allocator>::value, int> = 0 >
flat_set(sorted_unique_range_t, std::initializer_list<Key>, Compare = Compare(), Allocator = Allocator())
-> flat_set<Key, Compare>;
}
namespace flat_hpp
{
template < typename Key

View File

@@ -11,7 +11,7 @@ lcov -d . -z
ctest --verbose
lcov -d . -c -o "coverage.info"
lcov -r "coverage.info" "*/usr/*" "*/catch.hpp" "*/catch_main.cpp" "*_tests.cpp" "*_examples.cpp" -o "coverage.info"
lcov -r "coverage.info" "*/usr/*" "*/doctest/*" "*/untests/*" -o "coverage.info"
lcov -l "coverage.info"
bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
bash <(curl -s https://codecov.io/bash) -f "coverage.info" || echo "Codecov did not collect coverage reports"

View File

@@ -1,6 +1,3 @@
# 3.11 version is required for `FetchContent`
cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
project(flat.hpp.untests)
#
@@ -32,20 +29,3 @@ target_compile_options(${PROJECT_NAME}
-Wall -Wextra -Wpedantic>)
add_test(${PROJECT_NAME} ${PROJECT_NAME})
#
# catchorg/catch2
#
include(FetchContent)
FetchContent_Declare(
catchorg_catch2
GIT_REPOSITORY https://github.com/catchorg/catch2
GIT_TAG v2.13.2)
FetchContent_GetProperties(catchorg_catch2)
if(NOT catchorg_catch2_POPULATED)
FetchContent_Populate(catchorg_catch2)
target_include_directories(${PROJECT_NAME}
PRIVATE ${catchorg_catch2_SOURCE_DIR}/single_include)
endif()

6260
untests/doctest/doctest.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -4,19 +4,19 @@
* Copyright (C) 2019-2020, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#define CATCH_CONFIG_FAST_COMPILE
#include <catch2/catch.hpp>
#include <flat.hpp/flat_map.hpp>
#include "doctest/doctest.h"
#include "flat_tests.hpp"
#include <deque>
#include <string>
#include <string_view>
#include <flat.hpp/flat_map.hpp>
using namespace flat_hpp;
namespace
{
using namespace flat_hpp;
template < typename T >
class dummy_less {
public:
@@ -57,11 +57,114 @@ namespace
}
TEST_CASE("flat_map") {
SECTION("detail") {
SUBCASE("guides") {
{
std::vector<std::pair<int,unsigned>> vs;
auto s0 = flat_map(vs.begin(), vs.end());
auto s1 = flat_map(flat_hpp::sorted_range, vs.begin(), vs.end());
auto s2 = flat_map(flat_hpp::sorted_unique_range, vs.begin(), vs.end());
auto s3 = flat_map(vs.begin(), vs.end(), std::less<int>());
auto s4 = flat_map(flat_hpp::sorted_range, vs.begin(), vs.end(), std::less<int>());
auto s5 = flat_map(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::less<int>());
auto s6 = flat_map(vs.begin(), vs.end(), std::allocator<int>());
auto s7 = flat_map(flat_hpp::sorted_range, vs.begin(), vs.end(), std::allocator<int>());
auto s8 = flat_map(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::allocator<int>());
auto s9 = flat_map(vs.begin(), vs.end(), std::less<int>(), std::allocator<int>());
auto s10 = flat_map(flat_hpp::sorted_range, vs.begin(), vs.end(), std::less<int>(), std::allocator<int>());
auto s11 = flat_map(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::less<int>(), std::allocator<int>());
STATIC_REQUIRE(std::is_same_v<decltype(s0)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s4)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s5)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s6)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s7)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s8)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s9)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s10)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s11)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s0)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s1)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s4)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s5)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s6)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s7)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s8)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s9)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s10)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s11)::mapped_type, unsigned>);
}
{
auto s1 = flat_map({std::pair{1,1u}, std::pair{2,2u}});
auto s2 = flat_map(flat_hpp::sorted_range, {std::pair{1,1u}, std::pair{2,2u}});
auto s3 = flat_map(flat_hpp::sorted_unique_range, {std::pair{1,1u}, std::pair{2,2u}});
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s1)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::mapped_type, unsigned>);
}
{
auto s1 = flat_map({std::pair{1,1u}, std::pair{2,2u}}, std::less<int>());
auto s2 = flat_map(flat_hpp::sorted_range, {std::pair{1,1u}, std::pair{2,2u}}, std::less<int>());
auto s3 = flat_map(flat_hpp::sorted_unique_range, {std::pair{1,1u}, std::pair{2,2u}}, std::less<int>());
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s1)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::mapped_type, unsigned>);
}
{
auto s1 = flat_map({std::pair{1,1u}, std::pair{2,2u}}, std::allocator<int>());
auto s2 = flat_map(flat_hpp::sorted_range, {std::pair{1,1u}, std::pair{2,2u}}, std::allocator<int>());
auto s3 = flat_map(flat_hpp::sorted_unique_range, {std::pair{1,1u}, std::pair{2,2u}}, std::allocator<int>());
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s1)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::mapped_type, unsigned>);
}
{
auto s1 = flat_map({std::pair{1,1u}, std::pair{2,2u}}, std::less<int>(), std::allocator<int>());
auto s2 = flat_map(flat_hpp::sorted_range, {std::pair{1,1u}, std::pair{2,2u}}, std::less<int>(), std::allocator<int>());
auto s3 = flat_map(flat_hpp::sorted_unique_range, {std::pair{1,1u}, std::pair{2,2u}}, std::less<int>(), std::allocator<int>());
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s1)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::mapped_type, unsigned>);
}
}
SUBCASE("detail") {
STATIC_REQUIRE(detail::is_transparent<std::less<>, int>::value);
STATIC_REQUIRE_FALSE(detail::is_transparent<std::less<int>, int>::value);
}
SECTION("sizeof") {
SUBCASE("sizeof") {
REQUIRE(sizeof(flat_map<int, unsigned>) == sizeof(std::vector<std::pair<int, unsigned>>));
struct vc : flat_map<int, unsigned>::value_compare {
@@ -69,7 +172,7 @@ TEST_CASE("flat_map") {
};
REQUIRE(sizeof(vc) == sizeof(int));
}
SECTION("noexcept") {
SUBCASE("noexcept") {
using alloc_t = std::allocator<std::pair<int,unsigned>>;
using map_t = flat_map<int, unsigned, dummy_less<int>, std::vector<std::pair<int,unsigned>, alloc_t>>;
using map2_t = flat_map<int, unsigned, dummy_less2<int>>;
@@ -103,7 +206,7 @@ TEST_CASE("flat_map") {
STATIC_REQUIRE(noexcept(std::declval<map_t&>().clear()));
}
SECTION("types") {
SUBCASE("types") {
using map_t = flat_map<int, unsigned>;
STATIC_REQUIRE(std::is_same_v<map_t::key_type, int>);
@@ -119,7 +222,7 @@ TEST_CASE("flat_map") {
STATIC_REQUIRE(std::is_same_v<map_t::pointer, std::pair<int, unsigned>*>);
STATIC_REQUIRE(std::is_same_v<map_t::const_pointer, const std::pair<int, unsigned>*>);
}
SECTION("ctors") {
SUBCASE("ctors") {
using alloc_t = std::allocator<
std::pair<int,unsigned>>;
@@ -210,7 +313,7 @@ TEST_CASE("flat_map") {
REQUIRE(s1 == map_t{{1,4},{2,3},{3,1}});
}
}
SECTION("capacity") {
SUBCASE("capacity") {
using map_t = flat_map<int, unsigned>;
{
@@ -266,7 +369,7 @@ TEST_CASE("flat_map") {
REQUIRE(s1 == map2_t{{1,2},{2,3},{3,4}});
}
}
SECTION("access") {
SUBCASE("access") {
struct obj_t {
obj_t(int i) : i(i) {}
int i;
@@ -302,7 +405,7 @@ TEST_CASE("flat_map") {
REQUIRE_THROWS_AS(s0.at(0), std::out_of_range);
REQUIRE_THROWS_AS(my_as_const(s0).at(0), std::out_of_range);
}
SECTION("inserts") {
SUBCASE("inserts") {
struct obj_t {
obj_t(int i) : i(i) {}
int i;
@@ -398,7 +501,7 @@ TEST_CASE("flat_map") {
REQUIRE(s0 == map_t{{1,4}});
}
}
SECTION("erasers") {
SUBCASE("erasers") {
using map_t = flat_map<int, unsigned>;
{
map_t s0{{1,2},{2,3},{3,4}};
@@ -434,7 +537,7 @@ TEST_CASE("flat_map") {
REQUIRE(s1 == map_t{{2,3},{3,4},{5,6}});
}
}
SECTION("lookup") {
SUBCASE("lookup") {
using map_t = flat_map<int, unsigned>;
{
map_t s0{{1,2},{2,3},{3,4},{4,5},{5,6}};
@@ -469,7 +572,7 @@ TEST_CASE("flat_map") {
REQUIRE(my_as_const(s0).lower_bound(7) == s0.cbegin() + 3);
}
}
SECTION("heterogeneous") {
SUBCASE("heterogeneous") {
flat_map<std::string, int, std::less<>> s0{{"hello", 42}, {"world", 84}};
REQUIRE(s0.find(std::string_view("hello")) == s0.begin());
REQUIRE(my_as_const(s0).find(std::string_view("world")) == s0.begin() + 1);
@@ -488,7 +591,7 @@ TEST_CASE("flat_map") {
REQUIRE(s0.at(std::string_view("world")) == 84);
REQUIRE(my_as_const(s0).at(std::string_view("world")) == 84);
}
SECTION("observers") {
SUBCASE("observers") {
struct my_less {
int i;
my_less(int i) : i(i) {}
@@ -501,7 +604,7 @@ TEST_CASE("flat_map") {
REQUIRE(my_as_const(s0).key_comp().i == 42);
REQUIRE(my_as_const(s0).value_comp()({2,50},{4,20}));
}
SECTION("custom_less") {
SUBCASE("custom_less") {
using map_t = flat_map<int, unsigned, dummy_less<int>>;
auto s0 = map_t(dummy_less<int>(42));
auto s1 = map_t(dummy_less<int>(21));
@@ -511,7 +614,7 @@ TEST_CASE("flat_map") {
REQUIRE(s0.key_comp().i == 21);
REQUIRE(s1.key_comp().i == 42);
}
SECTION("operators") {
SUBCASE("operators") {
using map_t = flat_map<int, unsigned>;
REQUIRE(map_t{{1,2},{3,4}} == map_t{{3,4},{1,2}});

View File

@@ -4,19 +4,19 @@
* Copyright (C) 2019-2020, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#define CATCH_CONFIG_FAST_COMPILE
#include <catch2/catch.hpp>
#include <flat.hpp/flat_multimap.hpp>
#include "doctest/doctest.h"
#include "flat_tests.hpp"
#include <deque>
#include <string>
#include <string_view>
#include <flat.hpp/flat_multimap.hpp>
using namespace flat_hpp;
namespace
{
using namespace flat_hpp;
template < typename T >
class dummy_less {
public:
@@ -57,11 +57,114 @@ namespace
}
TEST_CASE("flat_multimap") {
SECTION("detail") {
SUBCASE("guides") {
{
std::vector<std::pair<int,unsigned>> vs;
auto s0 = flat_multimap(vs.begin(), vs.end());
auto s1 = flat_multimap(flat_hpp::sorted_range, vs.begin(), vs.end());
auto s2 = flat_multimap(flat_hpp::sorted_unique_range, vs.begin(), vs.end());
auto s3 = flat_multimap(vs.begin(), vs.end(), std::less<int>());
auto s4 = flat_multimap(flat_hpp::sorted_range, vs.begin(), vs.end(), std::less<int>());
auto s5 = flat_multimap(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::less<int>());
auto s6 = flat_multimap(vs.begin(), vs.end(), std::allocator<int>());
auto s7 = flat_multimap(flat_hpp::sorted_range, vs.begin(), vs.end(), std::allocator<int>());
auto s8 = flat_multimap(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::allocator<int>());
auto s9 = flat_multimap(vs.begin(), vs.end(), std::less<int>(), std::allocator<int>());
auto s10 = flat_multimap(flat_hpp::sorted_range, vs.begin(), vs.end(), std::less<int>(), std::allocator<int>());
auto s11 = flat_multimap(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::less<int>(), std::allocator<int>());
STATIC_REQUIRE(std::is_same_v<decltype(s0)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s4)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s5)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s6)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s7)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s8)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s9)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s10)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s11)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s0)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s1)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s4)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s5)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s6)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s7)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s8)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s9)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s10)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s11)::mapped_type, unsigned>);
}
{
auto s1 = flat_multimap({std::pair{1,1u}, std::pair{2,2u}});
auto s2 = flat_multimap(flat_hpp::sorted_range, {std::pair{1,1u}, std::pair{2,2u}});
auto s3 = flat_multimap(flat_hpp::sorted_unique_range, {std::pair{1,1u}, std::pair{2,2u}});
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s1)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::mapped_type, unsigned>);
}
{
auto s1 = flat_multimap({std::pair{1,1u}, std::pair{2,2u}}, std::less<int>());
auto s2 = flat_multimap(flat_hpp::sorted_range, {std::pair{1,1u}, std::pair{2,2u}}, std::less<int>());
auto s3 = flat_multimap(flat_hpp::sorted_unique_range, {std::pair{1,1u}, std::pair{2,2u}}, std::less<int>());
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s1)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::mapped_type, unsigned>);
}
{
auto s1 = flat_multimap({std::pair{1,1u}, std::pair{2,2u}}, std::allocator<int>());
auto s2 = flat_multimap(flat_hpp::sorted_range, {std::pair{1,1u}, std::pair{2,2u}}, std::allocator<int>());
auto s3 = flat_multimap(flat_hpp::sorted_unique_range, {std::pair{1,1u}, std::pair{2,2u}}, std::allocator<int>());
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s1)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::mapped_type, unsigned>);
}
{
auto s1 = flat_multimap({std::pair{1,1u}, std::pair{2,2u}}, std::less<int>(), std::allocator<int>());
auto s2 = flat_multimap(flat_hpp::sorted_range, {std::pair{1,1u}, std::pair{2,2u}}, std::less<int>(), std::allocator<int>());
auto s3 = flat_multimap(flat_hpp::sorted_unique_range, {std::pair{1,1u}, std::pair{2,2u}}, std::less<int>(), std::allocator<int>());
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s1)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::mapped_type, unsigned>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::mapped_type, unsigned>);
}
}
SUBCASE("detail") {
STATIC_REQUIRE(detail::is_transparent<std::less<>, int>::value);
STATIC_REQUIRE_FALSE(detail::is_transparent<std::less<int>, int>::value);
}
SECTION("sizeof") {
SUBCASE("sizeof") {
REQUIRE(sizeof(flat_multimap<int, unsigned>) == sizeof(std::vector<std::pair<int, unsigned>>));
struct vc : flat_multimap<int, unsigned>::value_compare {
@@ -69,7 +172,7 @@ TEST_CASE("flat_multimap") {
};
REQUIRE(sizeof(vc) == sizeof(int));
}
SECTION("noexcept") {
SUBCASE("noexcept") {
using alloc_t = std::allocator<std::pair<int,unsigned>>;
using map_t = flat_multimap<int, unsigned, dummy_less<int>, std::vector<std::pair<int,unsigned>, alloc_t>>;
using map2_t = flat_multimap<int, unsigned, dummy_less2<int>>;
@@ -103,7 +206,7 @@ TEST_CASE("flat_multimap") {
STATIC_REQUIRE(noexcept(std::declval<map_t&>().clear()));
}
SECTION("types") {
SUBCASE("types") {
using map_t = flat_multimap<int, unsigned>;
STATIC_REQUIRE(std::is_same_v<map_t::key_type, int>);
@@ -119,7 +222,7 @@ TEST_CASE("flat_multimap") {
STATIC_REQUIRE(std::is_same_v<map_t::pointer, std::pair<int, unsigned>*>);
STATIC_REQUIRE(std::is_same_v<map_t::const_pointer, const std::pair<int, unsigned>*>);
}
SECTION("ctors") {
SUBCASE("ctors") {
using alloc_t = std::allocator<
std::pair<int,unsigned>>;
@@ -210,7 +313,7 @@ TEST_CASE("flat_multimap") {
REQUIRE(s1 == map_t{{1,4},{2,3},{2,2},{3,1}});
}
}
SECTION("capacity") {
SUBCASE("capacity") {
using map_t = flat_multimap<int, unsigned>;
{
@@ -266,7 +369,7 @@ TEST_CASE("flat_multimap") {
REQUIRE(s1 == map2_t{{1,2},{2,3},{3,4}});
}
}
SECTION("access") {
SUBCASE("access") {
struct obj_t {
obj_t(int i) : i(i) {}
int i;
@@ -302,7 +405,7 @@ TEST_CASE("flat_multimap") {
REQUIRE_THROWS_AS(s0.at(0), std::out_of_range);
REQUIRE_THROWS_AS(my_as_const(s0).at(0), std::out_of_range);
}
SECTION("inserts") {
SUBCASE("inserts") {
struct obj_t {
obj_t(int i) : i(i) {}
int i;
@@ -370,7 +473,7 @@ TEST_CASE("flat_multimap") {
REQUIRE(s1 == map_t{{1,3},{2,2},{2,2},{3,1}});
}
}
SECTION("erasers") {
SUBCASE("erasers") {
using map_t = flat_multimap<int, unsigned>;
{
map_t s0{{1,2},{2,3},{3,4}};
@@ -407,7 +510,7 @@ TEST_CASE("flat_multimap") {
REQUIRE(s1 == map_t{{2,3},{3,4},{5,6}});
}
}
SECTION("lookup") {
SUBCASE("lookup") {
using map_t = flat_multimap<int, unsigned>;
{
map_t s0{{1,2},{2,3},{2,1},{3,4},{4,5},{5,6}};
@@ -443,7 +546,7 @@ TEST_CASE("flat_multimap") {
REQUIRE(my_as_const(s0).lower_bound(7) == s0.cbegin() + 4);
}
}
SECTION("heterogeneous") {
SUBCASE("heterogeneous") {
flat_multimap<std::string, int, std::less<>> s0{{"hello", 42}, {"world", 84}};
REQUIRE(s0.find(std::string_view("hello")) == s0.begin());
REQUIRE(my_as_const(s0).find(std::string_view("world")) == s0.begin() + 1);
@@ -462,7 +565,7 @@ TEST_CASE("flat_multimap") {
REQUIRE(s0.at(std::string_view("world")) == 84);
REQUIRE(my_as_const(s0).at(std::string_view("world")) == 84);
}
SECTION("observers") {
SUBCASE("observers") {
struct my_less {
int i;
my_less(int i) : i(i) {}
@@ -475,7 +578,7 @@ TEST_CASE("flat_multimap") {
REQUIRE(my_as_const(s0).key_comp().i == 42);
REQUIRE(my_as_const(s0).value_comp()({2,50},{4,20}));
}
SECTION("custom_less") {
SUBCASE("custom_less") {
using map_t = flat_multimap<int, unsigned, dummy_less<int>>;
auto s0 = map_t(dummy_less<int>(42));
auto s1 = map_t(dummy_less<int>(21));
@@ -485,7 +588,7 @@ TEST_CASE("flat_multimap") {
REQUIRE(s0.key_comp().i == 21);
REQUIRE(s1.key_comp().i == 42);
}
SECTION("operators") {
SUBCASE("operators") {
using map_t = flat_multimap<int, unsigned>;
REQUIRE(map_t{{1,2},{3,4}} == map_t{{3,4},{1,2}});

View File

@@ -4,19 +4,19 @@
* Copyright (C) 2019-2020, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#define CATCH_CONFIG_FAST_COMPILE
#include <catch2/catch.hpp>
#include <flat.hpp/flat_multiset.hpp>
#include "doctest/doctest.h"
#include "flat_tests.hpp"
#include <deque>
#include <string>
#include <string_view>
#include <flat.hpp/flat_multiset.hpp>
using namespace flat_hpp;
namespace
{
using namespace flat_hpp;
template < typename T >
class dummy_less {
public:
@@ -57,11 +57,85 @@ namespace
}
TEST_CASE("flat_multiset") {
SECTION("detail") {
SUBCASE("guides") {
{
std::vector<int> vs;
auto s0 = flat_multiset(vs.begin(), vs.end());
auto s1 = flat_multiset(flat_hpp::sorted_range, vs.begin(), vs.end());
auto s2 = flat_multiset(flat_hpp::sorted_unique_range, vs.begin(), vs.end());
auto s3 = flat_multiset(vs.begin(), vs.end(), std::less<int>());
auto s4 = flat_multiset(flat_hpp::sorted_range, vs.begin(), vs.end(), std::less<int>());
auto s5 = flat_multiset(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::less<int>());
auto s6 = flat_multiset(vs.begin(), vs.end(), std::allocator<int>());
auto s7 = flat_multiset(flat_hpp::sorted_range, vs.begin(), vs.end(), std::allocator<int>());
auto s8 = flat_multiset(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::allocator<int>());
auto s9 = flat_multiset(vs.begin(), vs.end(), std::less<int>(), std::allocator<int>());
auto s10 = flat_multiset(flat_hpp::sorted_range, vs.begin(), vs.end(), std::less<int>(), std::allocator<int>());
auto s11 = flat_multiset(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::less<int>(), std::allocator<int>());
STATIC_REQUIRE(std::is_same_v<decltype(s0)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s4)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s5)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s6)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s7)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s8)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s9)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s10)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s11)::key_type, int>);
}
{
auto s1 = flat_multiset({1, 2});
auto s2 = flat_multiset(flat_hpp::sorted_range, {1, 2});
auto s3 = flat_multiset(flat_hpp::sorted_unique_range, {1, 2});
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
}
{
auto s1 = flat_multiset({1, 2}, std::less<int>());
auto s2 = flat_multiset(flat_hpp::sorted_range, {1, 2}, std::less<int>());
auto s3 = flat_multiset(flat_hpp::sorted_unique_range, {1, 2}, std::less<int>());
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
}
{
auto s1 = flat_multiset({1, 2}, std::allocator<int>());
auto s2 = flat_multiset(flat_hpp::sorted_range, {1, 2}, std::allocator<int>());
auto s3 = flat_multiset(flat_hpp::sorted_unique_range, {1, 2}, std::allocator<int>());
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
}
{
auto s1 = flat_multiset({1, 2}, std::less<int>(), std::allocator<int>());
auto s2 = flat_multiset(flat_hpp::sorted_range, {1, 2}, std::less<int>(), std::allocator<int>());
auto s3 = flat_multiset(flat_hpp::sorted_unique_range, {1, 2}, std::less<int>(), std::allocator<int>());
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
}
}
SUBCASE("detail") {
STATIC_REQUIRE(detail::is_transparent<std::less<>, int>::value);
STATIC_REQUIRE_FALSE(detail::is_transparent<std::less<int>, int>::value);
}
SECTION("sizeof") {
SUBCASE("sizeof") {
REQUIRE(sizeof(flat_multiset<int>) == sizeof(std::vector<int>));
struct vc : flat_multiset<int>::value_compare {
@@ -69,7 +143,7 @@ TEST_CASE("flat_multiset") {
};
REQUIRE(sizeof(vc) == sizeof(int));
}
SECTION("noexcept") {
SUBCASE("noexcept") {
using alloc_t = std::allocator<int>;
using set_t = flat_multiset<int, dummy_less<int>, std::vector<int, alloc_t>>;
using set2_t = flat_multiset<int, dummy_less2<int>>;
@@ -103,7 +177,7 @@ TEST_CASE("flat_multiset") {
STATIC_REQUIRE(noexcept(std::declval<set_t&>().clear()));
}
SECTION("types") {
SUBCASE("types") {
using set_t = flat_multiset<int>;
STATIC_REQUIRE(std::is_same_v<set_t::key_type, int>);
@@ -118,7 +192,7 @@ TEST_CASE("flat_multiset") {
STATIC_REQUIRE(std::is_same_v<set_t::pointer, int*>);
STATIC_REQUIRE(std::is_same_v<set_t::const_pointer, const int*>);
}
SECTION("ctors") {
SUBCASE("ctors") {
using alloc_t = std::allocator<int>;
using set_t = flat_multiset<int, std::less<int>, std::vector<int, alloc_t>>;
using set2_t = flat_multiset<int, std::greater<int>, std::vector<int, alloc_t>>;
@@ -196,7 +270,7 @@ TEST_CASE("flat_multiset") {
REQUIRE(s1 == set_t{1,2,3,3});
}
}
SECTION("capacity") {
SUBCASE("capacity") {
using set_t = flat_multiset<int>;
{
@@ -250,7 +324,7 @@ TEST_CASE("flat_multiset") {
REQUIRE(s1 == set2_t{1,2,3});
}
}
SECTION("inserts") {
SUBCASE("inserts") {
struct obj_t {
obj_t(int i) : i(i) {}
int i;
@@ -346,7 +420,7 @@ TEST_CASE("flat_multiset") {
REQUIRE(s1 == set_t{1,2,2,3});
}
}
SECTION("erasers") {
SUBCASE("erasers") {
using set_t = flat_multiset<int>;
{
set_t s0{1,2,3,4,5};
@@ -383,7 +457,7 @@ TEST_CASE("flat_multiset") {
REQUIRE(s1 == set_t{3,4,5});
}
}
SECTION("lookup") {
SUBCASE("lookup") {
using set_t = flat_multiset<int>;
{
set_t s0{1,2,3,3,4,5};
@@ -419,7 +493,7 @@ TEST_CASE("flat_multiset") {
REQUIRE(my_as_const(s0).lower_bound(7) == s0.cbegin() + 4);
}
}
SECTION("heterogeneous") {
SUBCASE("heterogeneous") {
flat_multiset<std::string, std::less<>> s0{"hello", "world"};
REQUIRE(s0.find(std::string_view("hello")) == s0.begin());
REQUIRE(my_as_const(s0).find(std::string_view("world")) == s0.begin() + 1);
@@ -435,7 +509,7 @@ TEST_CASE("flat_multiset") {
REQUIRE(s0.upper_bound(std::string_view("hello")) == s0.begin() + 1);
REQUIRE(my_as_const(s0).upper_bound(std::string_view("hello")) == s0.begin() + 1);
}
SECTION("observers") {
SUBCASE("observers") {
struct my_less {
int i;
my_less(int i) : i(i) {}
@@ -448,7 +522,7 @@ TEST_CASE("flat_multiset") {
REQUIRE(my_as_const(s0).key_comp().i == 42);
REQUIRE(my_as_const(s0).value_comp().i == 42);
}
SECTION("custom_less") {
SUBCASE("custom_less") {
using set_t = flat_multiset<int, dummy_less<int>>;
auto s0 = set_t(dummy_less<int>(42));
auto s1 = set_t(dummy_less<int>(21));
@@ -458,7 +532,7 @@ TEST_CASE("flat_multiset") {
REQUIRE(s0.key_comp().i == 21);
REQUIRE(s1.key_comp().i == 42);
}
SECTION("operators") {
SUBCASE("operators") {
using set_t = flat_multiset<int>;
REQUIRE(set_t{1,2,3} == set_t{3,2,1});

View File

@@ -4,19 +4,19 @@
* Copyright (C) 2019-2020, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#define CATCH_CONFIG_FAST_COMPILE
#include <catch2/catch.hpp>
#include <flat.hpp/flat_set.hpp>
#include "doctest/doctest.h"
#include "flat_tests.hpp"
#include <deque>
#include <string>
#include <string_view>
#include <flat.hpp/flat_set.hpp>
using namespace flat_hpp;
namespace
{
using namespace flat_hpp;
template < typename T >
class dummy_less {
public:
@@ -57,11 +57,85 @@ namespace
}
TEST_CASE("flat_set") {
SECTION("detail") {
SUBCASE("guides") {
{
std::vector<int> vs;
auto s0 = flat_set(vs.begin(), vs.end());
auto s1 = flat_set(flat_hpp::sorted_range, vs.begin(), vs.end());
auto s2 = flat_set(flat_hpp::sorted_unique_range, vs.begin(), vs.end());
auto s3 = flat_set(vs.begin(), vs.end(), std::less<int>());
auto s4 = flat_set(flat_hpp::sorted_range, vs.begin(), vs.end(), std::less<int>());
auto s5 = flat_set(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::less<int>());
auto s6 = flat_set(vs.begin(), vs.end(), std::allocator<int>());
auto s7 = flat_set(flat_hpp::sorted_range, vs.begin(), vs.end(), std::allocator<int>());
auto s8 = flat_set(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::allocator<int>());
auto s9 = flat_set(vs.begin(), vs.end(), std::less<int>(), std::allocator<int>());
auto s10 = flat_set(flat_hpp::sorted_range, vs.begin(), vs.end(), std::less<int>(), std::allocator<int>());
auto s11 = flat_set(flat_hpp::sorted_unique_range, vs.begin(), vs.end(), std::less<int>(), std::allocator<int>());
STATIC_REQUIRE(std::is_same_v<decltype(s0)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s4)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s5)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s6)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s7)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s8)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s9)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s10)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s11)::key_type, int>);
}
{
auto s1 = flat_set({1, 2});
auto s2 = flat_set(flat_hpp::sorted_range, {1, 2});
auto s3 = flat_set(flat_hpp::sorted_unique_range, {1, 2});
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
}
{
auto s1 = flat_set({1, 2}, std::less<int>());
auto s2 = flat_set(flat_hpp::sorted_range, {1, 2}, std::less<int>());
auto s3 = flat_set(flat_hpp::sorted_unique_range, {1, 2}, std::less<int>());
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
}
{
auto s1 = flat_set({1, 2}, std::allocator<int>());
auto s2 = flat_set(flat_hpp::sorted_range, {1, 2}, std::allocator<int>());
auto s3 = flat_set(flat_hpp::sorted_unique_range, {1, 2}, std::allocator<int>());
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
}
{
auto s1 = flat_set({1, 2}, std::less<int>(), std::allocator<int>());
auto s2 = flat_set(flat_hpp::sorted_range, {1, 2}, std::less<int>(), std::allocator<int>());
auto s3 = flat_set(flat_hpp::sorted_unique_range, {1, 2}, std::less<int>(), std::allocator<int>());
STATIC_REQUIRE(std::is_same_v<decltype(s1)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s2)::key_type, int>);
STATIC_REQUIRE(std::is_same_v<decltype(s3)::key_type, int>);
}
}
SUBCASE("detail") {
STATIC_REQUIRE(detail::is_transparent<std::less<>, int>::value);
STATIC_REQUIRE_FALSE(detail::is_transparent<std::less<int>, int>::value);
}
SECTION("sizeof") {
SUBCASE("sizeof") {
REQUIRE(sizeof(flat_set<int>) == sizeof(std::vector<int>));
struct vc : flat_set<int>::value_compare {
@@ -69,7 +143,7 @@ TEST_CASE("flat_set") {
};
REQUIRE(sizeof(vc) == sizeof(int));
}
SECTION("noexcept") {
SUBCASE("noexcept") {
using alloc_t = std::allocator<int>;
using set_t = flat_set<int, dummy_less<int>, std::vector<int, alloc_t>>;
using set2_t = flat_set<int, dummy_less2<int>>;
@@ -103,7 +177,7 @@ TEST_CASE("flat_set") {
STATIC_REQUIRE(noexcept(std::declval<set_t&>().clear()));
}
SECTION("types") {
SUBCASE("types") {
using set_t = flat_set<int>;
STATIC_REQUIRE(std::is_same_v<set_t::key_type, int>);
@@ -118,7 +192,7 @@ TEST_CASE("flat_set") {
STATIC_REQUIRE(std::is_same_v<set_t::pointer, int*>);
STATIC_REQUIRE(std::is_same_v<set_t::const_pointer, const int*>);
}
SECTION("ctors") {
SUBCASE("ctors") {
using alloc_t = std::allocator<int>;
using set_t = flat_set<int, std::less<int>, std::vector<int, alloc_t>>;
using set2_t = flat_set<int, std::greater<int>, std::vector<int, alloc_t>>;
@@ -196,7 +270,7 @@ TEST_CASE("flat_set") {
REQUIRE(s1 == set_t{1,2,3});
}
}
SECTION("capacity") {
SUBCASE("capacity") {
using set_t = flat_set<int>;
{
@@ -250,7 +324,7 @@ TEST_CASE("flat_set") {
REQUIRE(s1 == set2_t{1,2,3});
}
}
SECTION("inserts") {
SUBCASE("inserts") {
struct obj_t {
obj_t(int i) : i(i) {}
int i;
@@ -346,7 +420,7 @@ TEST_CASE("flat_set") {
REQUIRE(s1 == set_t{1,2,3});
}
}
SECTION("erasers") {
SUBCASE("erasers") {
using set_t = flat_set<int>;
{
set_t s0{1,2,3,4,5};
@@ -382,7 +456,7 @@ TEST_CASE("flat_set") {
REQUIRE(s1 == set_t{3,4,5});
}
}
SECTION("lookup") {
SUBCASE("lookup") {
using set_t = flat_set<int>;
{
set_t s0{1,2,3,4,5};
@@ -417,7 +491,7 @@ TEST_CASE("flat_set") {
REQUIRE(my_as_const(s0).lower_bound(7) == s0.cbegin() + 3);
}
}
SECTION("heterogeneous") {
SUBCASE("heterogeneous") {
flat_set<std::string, std::less<>> s0{"hello", "world"};
REQUIRE(s0.find(std::string_view("hello")) == s0.begin());
REQUIRE(my_as_const(s0).find(std::string_view("world")) == s0.begin() + 1);
@@ -433,7 +507,7 @@ TEST_CASE("flat_set") {
REQUIRE(s0.upper_bound(std::string_view("hello")) == s0.begin() + 1);
REQUIRE(my_as_const(s0).upper_bound(std::string_view("hello")) == s0.begin() + 1);
}
SECTION("observers") {
SUBCASE("observers") {
struct my_less {
int i;
my_less(int i) : i(i) {}
@@ -446,7 +520,7 @@ TEST_CASE("flat_set") {
REQUIRE(my_as_const(s0).key_comp().i == 42);
REQUIRE(my_as_const(s0).value_comp().i == 42);
}
SECTION("custom_less") {
SUBCASE("custom_less") {
using set_t = flat_set<int, dummy_less<int>>;
auto s0 = set_t(dummy_less<int>(42));
auto s1 = set_t(dummy_less<int>(21));
@@ -456,7 +530,7 @@ TEST_CASE("flat_set") {
REQUIRE(s0.key_comp().i == 21);
REQUIRE(s1.key_comp().i == 42);
}
SECTION("operators") {
SUBCASE("operators") {
using set_t = flat_set<int>;
REQUIRE(set_t{1,2,3} == set_t{3,2,1});

View File

@@ -4,18 +4,18 @@
* Copyright (C) 2019-2020, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#define CATCH_CONFIG_FAST_COMPILE
#include <catch2/catch.hpp>
#include <flat.hpp/flat.hpp>
using namespace flat_hpp;
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest/doctest.h"
namespace
{
using namespace flat_hpp;
}
TEST_CASE("flat_map_detail") {
SECTION("is_sorted") {
SUBCASE("is_sorted") {
auto i1 = {1,2,3,4};
REQUIRE(detail::is_sorted(i1.begin(), i1.end(), std::less<int>()));
REQUIRE_FALSE(detail::is_sorted(i1.begin(), i1.end(), std::greater<int>()));
@@ -28,7 +28,7 @@ TEST_CASE("flat_map_detail") {
REQUIRE_FALSE(detail::is_sorted(i3.begin(), i3.end(), std::less<int>()));
REQUIRE_FALSE(detail::is_sorted(i3.begin(), i3.end(), std::greater<int>()));
}
SECTION("is_sorted_unique") {
SUBCASE("is_sorted_unique") {
auto i1 = {1,2,3,4};
auto i1d = {1,2,2,3,4};
REQUIRE(detail::is_sorted_unique(i1.begin(), i1.end(), std::less<int>()));

View File

@@ -4,6 +4,10 @@
* Copyright (C) 2019-2020, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#define CATCH_CONFIG_MAIN
#define CATCH_CONFIG_FAST_COMPILE
#include <catch2/catch.hpp>
#define STATIC_REQUIRE(...)\
static_assert(__VA_ARGS__, #__VA_ARGS__);\
REQUIRE(__VA_ARGS__);
#define STATIC_REQUIRE_FALSE(...)\
static_assert(!(__VA_ARGS__), "!(" #__VA_ARGS__ ")");\
REQUIRE(!(__VA_ARGS__));