BRICKS
Small, useful blocks of code, to build bigger things.
Loading...
Searching...
No Matches
contains.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <string>
5#include <type_traits>
6
8
9namespace bricks::detail {
10
14template <class Container, typename std::enable_if_t<
15 !has_find_v<Container, typename Container::value_type>, bool> = true>
16constexpr auto contains(const Container& container,
17 const typename Container::value_type& value) noexcept -> bool
18{
19 return std::find(std::begin(container), std::end(container), value) != std::end(container);
20}
21
25template <class Container, typename std::enable_if_t<
26 has_find_v<Container, typename Container::key_type>, bool> = true>
27constexpr auto contains(const Container& container,
28 const typename Container::key_type& key) noexcept -> bool
29{
30 return container.find(key) != std::end(container);
31}
32
36template <class CharT, class Traits = std::char_traits<CharT>,
37 class Allocator = std::allocator<CharT>>
38constexpr auto contains(const std::basic_string<CharT, Traits, Allocator>& str,
39 const CharT& value) noexcept -> bool
40{
41 return str.find(value) != std::basic_string<CharT, Traits, Allocator>::npos;
42}
43
44} // namespace bricks::detail
constexpr auto contains(const Container &container, const Value &value) noexcept -> bool
Checks whether a container contains a specific value.
Definition algorithm.hpp:95