I wrote the following code to determine if a type is an instantiation of std::basic_string
:
template <typename T>
struct is_string
{
enum { value = false };
};
template <typename charT, typename traits, typename Alloc>
struct is_string<std::basic_string<charT, traits, Alloc> >
{
enum { value = true };
};
Is there a more succinct way to achieve that?
Okay, I found a slightly shorter way:
#include <type_traits>
template <typename T>
struct is_string : std::false_type {};
template <typename charT, typename traits, typename Alloc>
struct is_string<std::basic_string<charT, traits, Alloc> > : std::true_type {};
But maybe others can do even better? :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With