Opened 10 years ago
Closed 10 years ago
#7775 closed Feature Requests (wontfix)
Allow algorithm::join to accept a container of char*
Reported by: | Sergey Mitsyn <svm at jinr.ru> | Owned by: | Marshall Clow |
---|---|---|---|
Milestone: | To Be Determined | Component: | algorithm |
Version: | Boost 1.52.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Sometimes it would be nice to join strings in this way:
const char *names[] = {"Jane", "John", "Kate", "Kyle"}; std::cout << boost::algorithm::join(names, ", ") << std::endl;
Can join be fixed to accept char*[]?
I think that one possible change would be in using a wrapper for a range_value<> that would return std::basic_string for a range_value<>::type which is a T* and range_value<>::type if it is something else. Anyway invoking join with a range value of T* with T not representing a character data is erroneous.
Another option is to use the result of evaluation of operator+(range_value, separator) - so a user can pass std::string in the case above to make it valid, but I'm not sure if this is possible and/or portable.
Change History (3)
comment:2 by , 10 years ago
Replying to marshall:
The problem is not creating from an array of
char *
, but from a container ofchar *
.
boost::algorithm::join
takes a "container (A) of containers (B)" and returns a "container (B)".When the (B) container is just "char *", it has no facility for creating such a container.
std::string arr[] = { "Hi", "Mom" }; boost::algorithm::join(arr, ", ");works fine (and returns a
std::string
)
Yep, that works perfectly! Didn't know c++03 allows that. Thanks!
comment:3 by , 10 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
The problem is not creating from an array of
char *
, but from a container ofchar *
.boost::algorithm::join
takes a "container (A) of containers (B)" and returns a "container (B)".When the (B) container is just "char *", it has no facility for creating such a container.
works fine (and returns a
std::string
)does not.