pstore2
inherit_const.hpp
Go to the documentation of this file.
1 //===- include/pstore/support/inherit_const.hpp -----------*- mode: C++ -*-===//
2 //* _ _ _ _ _ *
3 //* (_)_ __ | |__ ___ _ __(_) |_ ___ ___ _ __ ___| |_ *
4 //* | | '_ \| '_ \ / _ \ '__| | __| / __/ _ \| '_ \/ __| __| *
5 //* | | | | | | | | __/ | | | |_ | (_| (_) | | | \__ \ |_ *
6 //* |_|_| |_|_| |_|\___|_| |_|\__| \___\___/|_| |_|___/\__| *
7 //* *
8 //===----------------------------------------------------------------------===//
9 //
10 // Part of the pstore project, under the Apache License v2.0 with LLVM Exceptions.
11 // See https://github.com/SNSystems/pstore/blob/master/LICENSE.txt for license
12 // information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //===----------------------------------------------------------------------===//
92 
93 #ifndef PSTORE_SUPPORT_INHERIT_CONST_HPP
94 #define PSTORE_SUPPORT_INHERIT_CONST_HPP
95 
96 #include <type_traits>
97 
98 namespace pstore {
99 
107  template <typename T, typename R, typename RC = R const>
108  struct inherit_const {
110  using type =
111  typename std::conditional<std::is_const<typename std::remove_reference<T>::type>::value,
112  RC, R>::type;
113  };
114 
115 } // namespace pstore
116 
117 static_assert (std::is_same<typename pstore::inherit_const<int, bool>::type, bool>::value,
118  "int -> bool");
119 static_assert (
120  std::is_same<typename pstore::inherit_const<int const, bool>::type, bool const>::value,
121  "int const -> bool const");
122 static_assert (std::is_same<typename pstore::inherit_const<int &, bool>::type, bool>::value,
123  "int& -> bool");
124 static_assert (
125  std::is_same<typename pstore::inherit_const<int const &, bool>::type, bool const>::value,
126  "int const & -> bool const");
127 static_assert (std::is_same<typename pstore::inherit_const<int &&, bool>::type, bool>::value,
128  "int && -> bool");
129 static_assert (
130  std::is_same<typename pstore::inherit_const<int const &&, bool>::type, bool const>::value,
131  "int const && -> bool const");
132 
133 #endif // PSTORE_SUPPORT_INHERIT_CONST_HPP
Definition: nonpod2.cpp:40
Provides a member typedef inherit_const::type, which is defined as R const if T is a const type and R...
Definition: inherit_const.hpp:108
typename std::conditional< std::is_const< typename std::remove_reference< T >::type >::value, RC, R >::type type
If T is const, R const otherwise R.
Definition: inherit_const.hpp:112