mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 15:14:39 +00:00
Constrain Argument constructor better
Without this change, std::allocator can construct Argument
This commit is contained in:
parent
556d935491
commit
4c5ded8c84
@ -69,6 +69,11 @@ struct is_container<
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
static constexpr bool is_container_v = is_container<T>::value;
|
static constexpr bool is_container_v = is_container<T>::value;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
struct is_string_like
|
||||||
|
: std::conjunction<std::is_constructible<std::string, T>,
|
||||||
|
std::is_convertible<T, std::string_view>> {};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using enable_if_container = std::enable_if_t<is_container_v<T>, T>;
|
using enable_if_container = std::enable_if_t<is_container_v<T>, T>;
|
||||||
|
|
||||||
@ -115,8 +120,7 @@ public:
|
|||||||
|
|
||||||
template <typename... Args,
|
template <typename... Args,
|
||||||
std::enable_if_t<
|
std::enable_if_t<
|
||||||
std::conjunction_v<std::is_constructible<std::string, Args>...>,
|
std::conjunction_v<details::is_string_like<Args>...>, int> = 0>
|
||||||
int> = 0>
|
|
||||||
explicit Argument(Args &&... args)
|
explicit Argument(Args &&... args)
|
||||||
: Argument({std::string(std::forward<Args>(args))...},
|
: Argument({std::string(std::forward<Args>(args))...},
|
||||||
std::make_index_sequence<sizeof...(Args)>{}) {}
|
std::make_index_sequence<sizeof...(Args)>{}) {}
|
||||||
|
Loading…
Reference in New Issue
Block a user