mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
add subscript_at function
This commit is contained in:
parent
8278a2642c
commit
0080332dd5
12 changed files with 341 additions and 54 deletions
37
sprout/detail/functional/const_subscript.hpp
Normal file
37
sprout/detail/functional/const_subscript.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2016 Bolero MURAKAMI
|
||||
https://github.com/bolero-MURAKAMI/Sprout
|
||||
|
||||
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)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_DETAIL_FUNCTIONAL_CONST_SUBSCRIPT_HPP
|
||||
#define SPROUT_DETAIL_FUNCTIONAL_CONST_SUBSCRIPT_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/as_const.hpp>
|
||||
#include <sprout/functional/transparent.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename T = void>
|
||||
struct const_subscript;
|
||||
template<>
|
||||
struct const_subscript<void>
|
||||
: public sprout::transparent<>
|
||||
{
|
||||
public:
|
||||
template<typename T, typename U>
|
||||
SPROUT_CONSTEXPR decltype(std::declval<T>()[std::declval<U>()])
|
||||
operator()(T&& x, U&& y)
|
||||
const SPROUT_NOEXCEPT_IF_EXPR(const_cast<decltype(std::declval<T>()[std::declval<U>()])>(sprout::as_const(std::declval<T>())[std::declval<U>()]))
|
||||
{
|
||||
return const_cast<decltype(std::declval<T>()[std::declval<U>()])>(sprout::as_const(x)[SPROUT_FORWARD(U, y)]);
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_DETAIL_FUNCTIONAL_CONST_SUBSCRIPT_HPP
|
Loading…
Add table
Add a link
Reference in a new issue