6#include <boost/current_function.hpp>
8#include <userver/utils/text_light.hpp>
10USERVER_NAMESPACE_BEGIN
15constexpr std::string_view kExpectedPrefix =
16 "postgres::detail::IsInNamespaceImpl(std::string_view) [T = ";
18constexpr std::string_view kExpectedPrefix =
19 "postgres::detail::IsInNamespaceImpl(std::string_view) [with T = ";
23constexpr bool IsInNamespaceImpl(std::string_view nsp) {
24 using USERVER_NAMESPACE::utils::
text::StartsWith;
25 constexpr std::string_view fname = BOOST_CURRENT_FUNCTION;
26 constexpr auto pos = fname.find(kExpectedPrefix);
27 if (pos == std::string_view::npos) {
30 constexpr std::string_view fname_short{fname.data() + pos,
32 static_assert(!fname_short.empty(),
33 "Your compiler produces an unexpected function pretty name");
34 return StartsWith(fname_short.substr(kExpectedPrefix.size()), nsp) &&
35 StartsWith(fname_short.substr(kExpectedPrefix.size() + nsp.size()),
40constexpr bool IsInNamespace(std::string_view nsp) {
41 return IsInNamespaceImpl<std::remove_const_t<std::decay_t<T>>>(nsp);
45inline constexpr bool kIsInStdNamespace = IsInNamespace<T>(
"std");
47inline constexpr bool kIsInBoostNamespace = IsInNamespace<T>(
"boost");