Originally Posted by
medievalelks
How would you implement that on a generic type?
to_upper<Beeble>(myBeeble); // does what?
Is Beeble string-like? Does it provide an iterator over code points and a +=(codepoint) operator? (That's one possible defintion of StringLike.)
Code:
concept StringLike<S>
{
requires DefaultConstructible<S>;
requires Movable<S>;
typename const_iterator;
requires ForwardIterator<const_iterator>;
requires SameType<const_iterator::value_type, codepoint_t>;
const_iterator begin(S);
const_iterator end(S);
S &operator +=(S &, codepoint_t);
}
template <StringLike S>
S to_upper(const S &s)
{
S out;
for(StringLike<S>::const_iterator it = begin(s); it != end(s); ++it) {
out += codepoint_to_upper(*it);
}
return out;
}
std::basic_string<codepoint_t> is just one possible implementation of this concept.