6#include <boost/current_function.hpp>
10namespace storages::
postgres::detail {
13constexpr std::string_view kExpectedPrefix =
14 "postgres::detail::IsInNamespaceImpl(std::string_view) [T = ";
16constexpr std::string_view kExpectedPrefix =
17 "postgres::detail::IsInNamespaceImpl(std::string_view) [with T = ";
20constexpr bool StartsWith(std::string_view haystack, std::string_view needle) {
21 return haystack.substr(0, needle.size()) == needle;
25constexpr bool IsInNamespaceImpl(std::string_view nsp) {
26 constexpr std::string_view fname = BOOST_CURRENT_FUNCTION;
27 constexpr auto pos = fname.find(kExpectedPrefix);
28 if (pos == std::string_view::npos) {
31 constexpr std::string_view fname_short{fname.data() + pos,
33 static_assert(!fname_short.empty(),
34 "Your compiler produces an unexpected function pretty name");
35 return StartsWith(fname_short.substr(kExpectedPrefix.size()), nsp) &&
36 StartsWith(fname_short.substr(kExpectedPrefix.size() + nsp.size()),
41constexpr bool IsInNamespace(std::string_view nsp) {
42 return IsInNamespaceImpl<std::remove_const_t<std::decay_t<T>>>(nsp);
46inline constexpr bool kIsInStdNamespace = IsInNamespace<T>(
"std");
48inline constexpr bool kIsInBoostNamespace = IsInNamespace<T>(
"boost");