Skip to content

Commit

Permalink
Improve ATL/MFC string input support for C++17
Browse files Browse the repository at this point in the history
Add support for any strings derived from CSimpleStringT when using C++17
compilers.
  • Loading branch information
rmisev committed Oct 27, 2024
1 parent 0200557 commit a4b63b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
6 changes: 6 additions & 0 deletions include/upa/str_arg.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ constexpr bool is_size_type_v =
std::is_convertible_v<SizeT, std::size_t> ||
std::is_convertible_v<SizeT, std::ptrdiff_t>;

// See: https://en.cppreference.com/w/cpp/concepts/derived_from
template<class Derived, class Base>
constexpr bool is_derived_from_v =
std::is_base_of_v<Base, Derived> &&
std::is_convertible_v<const volatile Derived*, const volatile Base*>;


// string args helper class

Expand Down
21 changes: 9 additions & 12 deletions include/upa/url_for_atl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#ifdef UPA_CPP_20
# include <concepts>
#else
# include <cstringt.h>
# include <type_traits>
#endif

namespace upa {
Expand Down Expand Up @@ -43,17 +43,14 @@ struct str_arg_char<StrT> : public str_arg_char_for_atl<StrT> {};

#else // UPA_CPP_20

template<typename CharT, bool mfcdll>
struct str_arg_char<ATL::CSimpleStringT<CharT, mfcdll>> :
public str_arg_char_for_atl<ATL::CSimpleStringT<CharT, mfcdll>> {};

template<typename CharT, class StringTraits>
struct str_arg_char<ATL::CStringT<CharT, StringTraits>> :
public str_arg_char_for_atl<ATL::CStringT<CharT, StringTraits>> {};

template<class StrT, int nChars>
struct str_arg_char<ATL::CFixedStringT<StrT, nChars>> :
public str_arg_char_for_atl<ATL::CFixedStringT<StrT, nChars>> {};
// CStringT and CFixedStringT are derived from CSimpleStringT
template<class StrT>
struct str_arg_char<StrT, std::enable_if_t<
is_derived_from_v<StrT, ATL::CSimpleStringT<char, true>> ||
is_derived_from_v<StrT, ATL::CSimpleStringT<wchar_t, true>> ||
is_derived_from_v<StrT, ATL::CSimpleStringT<char, false>> ||
is_derived_from_v<StrT, ATL::CSimpleStringT<wchar_t, false>>
>> : public str_arg_char_for_atl<StrT> {};

#endif // UPA_CPP_20

Expand Down

0 comments on commit a4b63b2

Please sign in to comment.