Danny Robson
f6056153e3
This places, at long last, the core library code into the same namespace as the extended library code.
46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*
|
|
* Copyright 2018 Danny Robson <danny@nerdcruft.net>
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <utility>
|
|
|
|
|
|
namespace cruft::functor {
|
|
///////////////////////////////////////////////////////////////////////////
|
|
/// returns the value provided at construction time regardless of the
|
|
/// arguments supplied in the call operator.
|
|
template <typename ValueT>
|
|
class constant {
|
|
public:
|
|
constant (const ValueT &_value):
|
|
m_value (_value)
|
|
{ ; }
|
|
|
|
|
|
template <typename ...Args>
|
|
ValueT&
|
|
operator() (Args&&...) noexcept
|
|
{ return m_value; }
|
|
|
|
|
|
template <typename ...Args>
|
|
const ValueT&
|
|
operator() (Args&&...) const noexcept
|
|
{ return m_value; }
|
|
|
|
|
|
private:
|
|
ValueT m_value;
|
|
};
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
template <typename ValueT>
|
|
constant (ValueT) -> constant<std::decay_t<ValueT>>;
|
|
}; |