I also put all the tic-tac-toe specific files into 'ttt' subdirectories to make it easier to see what's specifically for this game and what's just a wip idea
80 lines
2.3 KiB
C++
80 lines
2.3 KiB
C++
/**
|
|
This file is a part of our_dick
|
|
Copyright (C) 2022 rexy712
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef OUR_DICK_UTIL_DEFERRED_HPP
|
|
#define OUR_DICK_UTIL_DEFERRED_HPP
|
|
|
|
#include <tuple>
|
|
#include <utility> //forward, index_sequence
|
|
|
|
namespace util{
|
|
template<class T, class... Args>
|
|
class deferred
|
|
{
|
|
public:
|
|
using value_type = T;
|
|
|
|
private:
|
|
std::tuple<Args...> m_args;
|
|
|
|
public:
|
|
template<class... FArgs>
|
|
constexpr deferred(FArgs&&... args);
|
|
|
|
deferred(const deferred&) = default;
|
|
deferred(deferred&&) = default;
|
|
~deferred(void) = default;
|
|
deferred& operator=(const deferred&) = default;
|
|
deferred& operator=(deferred&&) = default;
|
|
|
|
constexpr value_type value(void);
|
|
constexpr operator value_type(void);
|
|
|
|
private:
|
|
template<size_t... Is>
|
|
constexpr value_type get_value_(std::index_sequence<Is...>);
|
|
};
|
|
|
|
template<class T, class... Args>
|
|
template<class... FArgs>
|
|
constexpr deferred<T,Args...>::deferred(FArgs&&... args):
|
|
m_args{std::forward<FArgs>(args)...}{}
|
|
template<class T, class... Args>
|
|
constexpr auto deferred<T,Args...>::value(void) -> deferred<T,Args...>::value_type{
|
|
return get_value_(std::make_index_sequence<sizeof...(Args)>());
|
|
}
|
|
template<class T, class... Args>
|
|
constexpr deferred<T,Args...>::operator value_type(void){
|
|
return get_value_(std::make_index_sequence<sizeof...(Args)>());
|
|
}
|
|
template<class T, class... Args>
|
|
template<size_t... Is>
|
|
constexpr auto deferred<T,Args...>::get_value_(std::index_sequence<Is...>) -> deferred<T,Args...>::value_type{
|
|
return T{std::get<Is>(m_args)...};
|
|
}
|
|
|
|
|
|
template<class T, class... Args>
|
|
deferred<T,Args...> make_deferred(Args&&... args){
|
|
return deferred<T,Args...>(std::forward<Args>(args)...);
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|