iterator/infix: avoid using references to temporaries in make_infix

This commit is contained in:
Danny Robson 2020-11-10 16:22:46 +10:00
parent 0fe14f038d
commit 17a85e8187

View File

@ -66,7 +66,7 @@ namespace cruft::iterator {
namespace detail { namespace detail {
template <typename ContainerT, typename CharT> template <typename ContainerT, typename CharT>
struct infix_t { struct infix_t {
const ContainerT &_container; ContainerT _container;
const CharT *_delimiter; const CharT *_delimiter;
}; };
@ -101,7 +101,18 @@ namespace cruft::iterator {
auto auto
make_infix (ContainerT const &_container, const CharT *_delimiter = ", ") make_infix (ContainerT const &_container, const CharT *_delimiter = ", ")
{ {
return detail::infix_t<ContainerT,CharT> { _container, _delimiter }; return detail::infix_t<ContainerT const&,CharT> { _container, _delimiter };
}
template <typename ContainerT, typename CharT = char>
auto
make_infix (ContainerT &&_container, const CharT *_delimiter = ", ")
{
return detail::infix_t<std::remove_reference_t<ContainerT>,CharT> {
std::forward<ContainerT> (_container),
_delimiter
};
} }