Skip to content

Array, Grid の推論補助を追加 #1309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: v6_develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Siv3D/include/Siv3D/Array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,18 @@ namespace s3d
template <class Type, class Allocator>
inline void swap(Array<Type, Allocator>& a, Array<Type, Allocator>& b) noexcept;

namespace detail
{
template <class>
struct IsNamedParameter : std::false_type {};

template <class Tag, class Type>
struct IsNamedParameter<NamedParameter<Tag, Type>> : std::true_type {};

template <class Type>
constexpr bool IsNamedParameter_v = IsNamedParameter<Type>::value;
}

// deduction guide
template <class Type, class Allocator = std::allocator<Type>>
Array(std::initializer_list<Type>, const Allocator& = Allocator{}) -> Array<Type, Allocator>;
Expand All @@ -1235,6 +1247,15 @@ namespace s3d
template <class Iterator, class Allocator = std::allocator<typename std::iterator_traits<Iterator>::value_type>>
Array(Iterator, Iterator, const Allocator& = Allocator{}) -> Array<typename std::iterator_traits<Iterator>::value_type, Allocator>;

template <class Type, class Allocator = std::allocator<Type>, std::enable_if_t<std::is_same_v<typename Allocator::value_type, Type> && (not detail::IsNamedParameter_v<Type>)>* = nullptr>
Array(typename Array<Type, Allocator>::size_type, const Type&, const Allocator& = Allocator{}) -> Array<Type, Allocator>;

template <class Fty>
Array(typename Array<std::decay_t<std::invoke_result_t<Fty>>>::size_type, Arg::generator_<Fty>) -> Array<std::decay_t<std::invoke_result_t<Fty>>>;

template <class Fty>
Array(typename Array<std::decay_t<std::invoke_result_t<Fty, size_t>>>::size_type, Arg::indexedGenerator_<Fty>) -> Array<std::decay_t<std::invoke_result_t<Fty, size_t>>>;

/// @brief
/// @tparam T0
/// @tparam ...Ts
Expand Down
18 changes: 18 additions & 0 deletions Siv3D/include/Siv3D/Grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,24 @@ namespace s3d
template <class Type>
Grid(Size, Array<Type>&&) -> Grid<Type>;

template <class Type, std::enable_if_t<not detail::IsNamedParameter_v<Type>>* = nullptr>
Grid(typename Grid<Type>::size_type, typename Grid<Type>::size_type, const Type&) -> Grid<Type>;

template <class Type, std::enable_if_t<not detail::IsNamedParameter_v<Type>>* = nullptr>
Grid(Size, const Type&) -> Grid<Type>;

template <class Fty>
Grid(typename Grid<std::decay_t<std::invoke_result_t<Fty>>>::size_type, typename Grid<std::decay_t<std::invoke_result_t<Fty>>>::size_type, Arg::generator_<Fty>) -> Grid<std::decay_t<std::invoke_result_t<Fty>>>;

template <class Fty>
Grid(Size, Arg::generator_<Fty>) -> Grid<std::decay_t<std::invoke_result_t<Fty>>>;

template <class Fty>
Grid(typename Grid<std::decay_t<std::invoke_result_t<Fty, Point>>>::size_type, typename Grid<std::decay_t<std::invoke_result_t<Fty, Point>>>::size_type, Arg::indexedGenerator_<Fty>) -> Grid<std::decay_t<std::invoke_result_t<Fty, Point>>>;

template <class Fty>
Grid(Size, Arg::indexedGenerator_<Fty>) -> Grid<std::decay_t<std::invoke_result_t<Fty, Point>>>;

template <class Type, class Allocator>
inline void swap(Grid<Type, Allocator>& a, Grid<Type, Allocator>& b) noexcept;
}
Expand Down