Last active
May 17, 2018 16:40
-
-
Save oliora/f26694bb61d631687dfe1a1646351898 to your computer and use it in GitHub Desktop.
Function fallback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::string wstr_to_utf8(boost::wstring_view); | |
namespace detail { | |
template<class T, class = void> | |
struct narrow_impl | |
{ | |
template<class U> | |
static U&& invoke(U&& s) noexcept | |
{ | |
static_assert(std::is_same<T, U&&>::value, "error"); | |
return std::forward<U>(s); | |
} | |
}; | |
template<class T> | |
struct narrow_impl<T, void_t<decltype(wstr_to_utf8(std::declval<T>()))>> | |
{ | |
template<class U> | |
static auto invoke(U&& s) -> decltype(wstr_to_utf8(std::forward<U>(s))) | |
{ | |
static_assert(std::is_same<T, U&&>::value, "error"); | |
return wstr_to_utf8(std::forward<U>(s)); | |
} | |
}; | |
} | |
template<class T> | |
inline auto narrow(T&& s) -> decltype(detail::narrow_impl<T&&>::invoke(std::forward<T>(s))) | |
{ | |
return detail::narrow_impl<T&&>::invoke(std::forward<T>(s)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment