Skip to content

Commit e0f0489

Browse files
committed
#33 - Implement method CppStringT::join()
Completed.
1 parent 4ee68e3 commit e0f0489

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

cpp-strings/cppstrings.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <span>
2929
#include <stdexcept>
3030
#include <string_view>
31+
#include <type_traits>
3132
#include <vector>
3233

3334

@@ -553,6 +554,31 @@ namespace pcs // i.e. "pythonic c++ strings"
553554
}
554555

555556

557+
//--- join() ------------------------------------------
558+
/** \brief Returns a string which is the concatenation of the strings in the parameters list.
559+
*
560+
* The separator between elements is the string to which this method is applied.
561+
*/
562+
template<class... NextCppStringsT>
563+
inline CppStringT join(const CppStringT& first, const NextCppStringsT... others) const noexcept
564+
requires (sizeof...(others) > 0)
565+
{
566+
return first + *this + this->join(others...);
567+
}
568+
569+
/** \brief A single parameter signature. Returns a copy of this parameter. */
570+
inline const CppStringT join(const CppStringT& s) const noexcept
571+
{
572+
return s;
573+
}
574+
575+
/** \brief Empty parameters list signature. Returns a copy of current string. */
576+
inline const CppStringT join() const noexcept
577+
{
578+
return *this;
579+
}
580+
581+
556582
//--- lower () -----------------------------------------
557583
/** \brief In-place replaces all characters of the string with their lowercase conversion. Returns a reference to string.
558584
*

0 commit comments

Comments
 (0)