17#ifndef LIB_BUG_HELPER_H_ 
   18#define LIB_BUG_HELPER_H_ 
   25#include <boost/format.hpp> 
   27#include "absl/strings/str_cat.h" 
   29#include "source_file.h" 
   34static inline std::pair<std::string_view, std::string> getPositionTail(
const Util::SourceInfo &info,
 
   35                                                                       std::string_view position,
 
   36                                                                       std::string_view tail) {
 
   37    std::string_view posString = info.toPositionString().string_view();
 
   38    std::string outTail(tail);
 
   39    if (position.empty()) {
 
   42        outTail.append(posString);
 
   43        if (!posString.empty()) outTail.append(
"\n");
 
   45    outTail += info.toSourceFragment();
 
   47    return std::pair(position, outTail);
 
   51std::pair<std::string_view, std::string> maybeAddSourceInfo(
const T &t, std::string_view position,
 
   52                                                            std::string_view tail) {
 
   53    if constexpr (Util::has_SourceInfo_v<T>)
 
   54        return getPositionTail(t.getSourceInfo(), position, tail);
 
   61static inline std::string bug_helper(boost::format &f, std::string_view position,
 
   62                                     std::string_view tail) {
 
   63    return absl::StrCat(position, position.empty() ? 
"" : 
": ", boost::str(f), 
"\n", tail);
 
   66template <
typename T, 
class... Args>
 
   67auto bug_helper(boost::format &f, std::string_view position, std::string_view tail, 
const T *t,
 
   70template <
typename T, 
class... Args>
 
   71auto bug_helper(boost::format &f, std::string_view position, std::string_view tail, 
const T &t,
 
   72                Args &&...args) -> std::enable_if_t<!std::is_pointer_v<T>, std::string>;
 
   74template <
class... Args>
 
   75std::string bug_helper(boost::format &f, std::string_view position, std::string_view tail,
 
   76                       const char *t, Args &&...args) {
 
   77    return bug_helper(f % t, position, tail, std::forward<Args>(args)...);
 
   80template <
class... Args>
 
   81std::string bug_helper(boost::format &f, std::string_view position, std::string_view tail,
 
   83    auto [outPos, outTail] = detail::getPositionTail(info, position, tail);
 
   84    return bug_helper(f % 
"", outPos, outTail, std::forward<Args>(args)...);
 
   87template <
typename T, 
class... Args>
 
   88auto bug_helper(boost::format &f, std::string_view position, std::string_view tail, 
const T *t,
 
   90    if (t == 
nullptr) 
return bug_helper(f, position, tail, std::forward<Args>(args)...);
 
   92    auto [outPos, outTail] = maybeAddSourceInfo(*t, position, tail);
 
  101    std::stringstream str;
 
  103    return bug_helper(f % str.str(), outPos, outTail, std::forward<Args>(args)...);
 
  106template <
typename T, 
class... Args>
 
  107auto bug_helper(boost::format &f, std::string_view position, std::string_view tail, 
const T &t,
 
  108                Args &&...args) -> std::enable_if_t<!std::is_pointer_v<T>, std::string> {
 
  109    auto [outPos, outTail] = maybeAddSourceInfo(t, position, tail);
 
  110    std::stringstream str;
 
  112    return bug_helper(f % str.str(), outPos, outTail, std::forward<Args>(args)...);
 
  117template <
class... Args>
 
  118std::string bug_helper(boost::format &f, std::string_view position, std::string_view tail,
 
  120    return detail::bug_helper(f, position, tail, std::forward<Args>(args)...);
 
Definition source_file.h:123