Skip to content

Commit

Permalink
Improve ATL/MFC string input support for C++11 ... C++17
Browse files Browse the repository at this point in the history
Add support for any strings derived from CSimpleStringT when using C++11
... C++17 compilers.
  • Loading branch information
rmisev committed Nov 7, 2024
1 parent 21ca170 commit 6bea3d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
7 changes: 7 additions & 0 deletions include/upa/str_arg.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ struct is_size_type : std::integral_constant<bool,
std::is_convertible<SizeT, std::ptrdiff_t>::value
> {};

// See: https://en.cppreference.com/w/cpp/concepts/derived_from
template<class Derived, class Base>
struct is_derived_from : std::integral_constant<bool,
std::is_base_of<Base, Derived>::value &&
std::is_convertible<const volatile Derived*, const volatile Base*>::value
> {};


// 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, typename std::enable_if<
is_derived_from<StrT, ATL::CSimpleStringT<char, true>>::value ||
is_derived_from<StrT, ATL::CSimpleStringT<wchar_t, true>>::value ||
is_derived_from<StrT, ATL::CSimpleStringT<char, false>>::value ||
is_derived_from<StrT, ATL::CSimpleStringT<wchar_t, false>>::value
>::type> : public str_arg_char_for_atl<StrT> {};

#endif // UPA_CPP_20

Expand Down

0 comments on commit 6bea3d3

Please sign in to comment.