Skip to content

Instantly share code, notes, and snippets.

View phetdam's full-sized avatar
㊙️
懐かしい曲、懐かしい青春

Derek Huang phetdam

㊙️
懐かしい曲、懐かしい青春
View GitHub Profile
@phetdam
phetdam / +to_wstring.cc
Last active December 4, 2022 00:45
The C++11 way to convert from string to wstring and back
template <typename Codecvt = std::codecvt_utf8<wchar_t>>
inline std::wstring to_wstring(const std::string& s)
{
std::wstring_convert<Codecvt> conv;
return conv.from_bytes(s);
}
@phetdam
phetdam / +size_constructible.cc
Last active December 3, 2022 03:56
SFINAE approach to checking if a Container is "size-constructible".
template <typename T, typename = void>
struct is_size_constructible : std::false_type {};
template <typename T>
struct is_size_constructible<T, std::void_t<typename T::size_type>>
: std::is_constructible<T, typename T::size_type> {};
template <typename T>
inline constexpr bool is_size_constructible_v = is_size_constructible<T>::value;
@phetdam
phetdam / +multi_typed_test.cc
Last active September 7, 2022 05:05
A way to use multiple types with the Google Test TYPED_TEST macro.
// `type_triple` specializations to use with TYPED_TEST for MultiTypedTest
using MultiTypedTestTypes = ::testing::Types<
type_triple<int, double, float>,
type_triple<char, std::string, size_t>,
type_triple<std::string, double, void *>
>;
// required macro to set up the typed test suite
TYPED_TEST_SUITE(MultiTypedTest, MultiTypedTestTypes);
@phetdam
phetdam / +dat_triple.cc
Last active September 7, 2022 04:38
A little bit of typename silliness.
template <typename T, typename U, typename V>
class func_type_triple {
public:
using type_a = T;
using type_b = U;
using type_c = V;
};
using dat_triple = func_type_triple<int, double, char>;