Skip to content

Commit

Permalink
libnixt/serialize: workaround for libcxx .view()
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Dec 30, 2023
1 parent 19fa773 commit 4caf753
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion libnixt/include/nixt/SerializeSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,29 @@ std::size_t write(std::ostream &OS, const T &Data) {
class StringTable {
public:
std::size_t write(std::string Str);
std::string_view view() { return OS.view(); }

// __WORKAROUND__: libcxx.view
// libcxx implements .view in recent patch:
// https://github.com/llvm/llvm-project/commit/81ad5a5cb87740c62b30a4f8232770bd5eb7fc45
// So on macOS this is not available.
std::string_view view() {
#if defined(__GLIBCXX__)
return OS.view();
#else
Data = OS.str();
return Data;
#endif
}

private:
std::map<std::string, std::size_t> Map;
std::ostringstream OS;

// __WORKAROUND__: libcxx.view
#if not defined(__GLIBCXX__)
std::string Data;
#endif

static std::size_t write(std::ostream &OS, const std::string &Data);

static std::size_t write(std::ostream &OS, const std::ostringstream &Data);
Expand Down

0 comments on commit 4caf753

Please sign in to comment.