Differential Revision: https://reviews.llvm.org/D159232 ``` Running ./ranges_contains.libcxx.out Run on (10 X 24.121 MHz CPU s) CPU Caches: L1 Data 64 KiB (x10) L1 Instruction 128 KiB (x10) L2 Unified 4096 KiB (x5) Load Average: 3.37, 6.77, 5.27 -------------------------------------------------------------------- Benchmark Time CPU Iterations -------------------------------------------------------------------- bm_contains_char/16 1.88 ns 1.87 ns 371607095 bm_contains_char/256 7.48 ns 7.47 ns 93292285 bm_contains_char/4096 99.7 ns 99.6 ns 7013185 bm_contains_char/65536 1296 ns 1294 ns 540436 bm_contains_char/1048576 23887 ns 23860 ns 29302 bm_contains_char/16777216 389420 ns 389095 ns 1796 bm_contains_int/16 7.14 ns 7.14 ns 97776288 bm_contains_int/256 90.4 ns 90.3 ns 7558089 bm_contains_int/4096 1294 ns 1290 ns 543052 bm_contains_int/65536 20482 ns 20443 ns 34334 bm_contains_int/1048576 328817 ns 327965 ns 2147 bm_contains_int/16777216 5246279 ns 5239361 ns 133 bm_contains_bool/16 2.19 ns 2.19 ns 322565780 bm_contains_bool/256 3.42 ns 3.41 ns 205025467 bm_contains_bool/4096 22.1 ns 22.1 ns 31780479 bm_contains_bool/65536 333 ns 332 ns 2106606 bm_contains_bool/1048576 5126 ns 5119 ns 135901 bm_contains_bool/16777216 81656 ns 81574 ns 8569 ``` --------- Co-authored-by: Nathan Gauër <brioche@google.com>
66 lines
1.8 KiB
C++
66 lines
1.8 KiB
C++
// -*- C++ -*-
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef _LIBCPP___FUNCTIONAL_IDENTITY_H
|
|
#define _LIBCPP___FUNCTIONAL_IDENTITY_H
|
|
|
|
#include <__config>
|
|
#include <__functional/reference_wrapper.h>
|
|
#include <__type_traits/integral_constant.h>
|
|
#include <__utility/forward.h>
|
|
|
|
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
|
# pragma GCC system_header
|
|
#endif
|
|
|
|
_LIBCPP_BEGIN_NAMESPACE_STD
|
|
|
|
template <class _Tp>
|
|
struct __is_identity : false_type {};
|
|
|
|
struct __identity {
|
|
template <class _Tp>
|
|
_LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR _Tp&& operator()(_Tp&& __t) const _NOEXCEPT {
|
|
return std::forward<_Tp>(__t);
|
|
}
|
|
|
|
using is_transparent = void;
|
|
};
|
|
|
|
template <>
|
|
struct __is_identity<__identity> : true_type {};
|
|
template <>
|
|
struct __is_identity<reference_wrapper<__identity> > : true_type {};
|
|
template <>
|
|
struct __is_identity<reference_wrapper<const __identity> > : true_type {};
|
|
|
|
#if _LIBCPP_STD_VER >= 20
|
|
|
|
struct identity {
|
|
template <class _Tp>
|
|
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr _Tp&& operator()(_Tp&& __t) const noexcept {
|
|
return std::forward<_Tp>(__t);
|
|
}
|
|
|
|
using is_transparent = void;
|
|
};
|
|
|
|
template <>
|
|
struct __is_identity<identity> : true_type {};
|
|
template <>
|
|
struct __is_identity<reference_wrapper<identity> > : true_type {};
|
|
template <>
|
|
struct __is_identity<reference_wrapper<const identity> > : true_type {};
|
|
|
|
#endif // _LIBCPP_STD_VER >= 20
|
|
|
|
_LIBCPP_END_NAMESPACE_STD
|
|
|
|
#endif // _LIBCPP___FUNCTIONAL_IDENTITY_H
|