diff --git a/src/cs_util.hh b/src/cs_util.hh index fcabc69..36a19cb 100644 --- a/src/cs_util.hh +++ b/src/cs_util.hh @@ -194,25 +194,39 @@ struct cs_strman { > counts; }; -struct cs_charbuf { - cs_charbuf() = delete; +template +struct cs_valbuf { + cs_valbuf() = delete; - cs_charbuf(cs_shared_state &cs): - buf{cs_shared_state::allocator{&cs}} + cs_valbuf(cs_shared_state &cs): + buf{cs_shared_state::allocator{&cs}} {} - cs_charbuf(cs_state &cs): - buf{cs_shared_state::allocator{cs_get_sstate(cs)}} + cs_valbuf(cs_state &cs): + buf{cs_shared_state::allocator{cs_get_sstate(cs)}} {} using size_type = std::size_t; - using value_type = char; - using reference = char &; - using const_reference = char const &; + using value_type = T; + using reference = T &; + using const_reference = T const &; void reserve(std::size_t s) { buf.reserve(s); } - void push_back(char c) { buf.push_back(c); } + void push_back(T const &v) { buf.push_back(v); } + + size_t size() const { return buf.size(); } + + bool empty() const { return buf.empty(); } + + void clear() { buf.clear(); } + + std::vector> buf; +}; + +struct cs_charbuf: cs_valbuf { + cs_charbuf(cs_shared_state &cs): cs_valbuf(cs) {} + cs_charbuf(cs_state &cs): cs_valbuf(cs) {} void append(char const *beg, char const *end) { buf.insert(buf.end(), beg, end); @@ -229,14 +243,6 @@ struct cs_charbuf { ostd::string_range str_term() { return ostd::string_range{buf.data(), buf.data() + buf.size() - 1}; } - - size_t size() const { return buf.size(); } - - bool empty() const { return buf.empty(); } - - void clear() { buf.clear(); } - - std::vector> buf; }; } /* namespace cscript */