瀏覽代碼

* Implemented string builder

master
bergmann 4 年之前
父節點
當前提交
67156bb213
共有 2 個檔案被更改,包括 56 行新增0 行删除
  1. +33
    -0
      include/cppcore/misc/string_builder.h
  2. +23
    -0
      include/cppcore/misc/string_builder.inl

+ 33
- 0
include/cppcore/misc/string_builder.h 查看文件

@@ -0,0 +1,33 @@
#pragma once

#include <sstream>

namespace cppcore
{

struct string_builder
{
private:
std::ostringstream os;

public:
/**
* @brief Write something to the string builder
*/
template<typename TArg>
string_builder& operator<<(TArg&& arg);

/**
* @brief Get the constructed string.
*/
inline std::string str() const;

/**
* @brief Get the constructed string.
*/
inline operator std::string() const;
};

}

#include "string_builder.inl"

+ 23
- 0
include/cppcore/misc/string_builder.inl 查看文件

@@ -0,0 +1,23 @@
#pragma once

#include "string_builder.h"

namespace cppcore
{

/* string_builder */

template<typename TArg>
string_builder& string_builder::operator<<(TArg&& arg)
{
os << std::forward<TArg>(arg);
return *this;
}

std::string string_builder::str() const
{ return os.str(); }

string_builder::operator std::string() const
{ return str(); }

}

Loading…
取消
儲存