concat icon indicating copy to clipboard operation
concat copied to clipboard

Possible enhancment: sequence delimiters

Open Bklyn opened this issue 10 years ago • 2 comments

So now that std::pair is supported, it would be great to be able to have different delimiters at the start/end of sequences in addition to between the elements of a sequence, so a list of tuples might be rendered like:

(1, 2, 3), (3, 2, 1), ....

Otherwise there's no way to distinguish this:

list<int> ints ({1, 2, 3, 4, 5, 6})
cout << concat (separator (","), ints) << "\n";

from this:

list<pair<int, int>> pairs ({{1, 2}, {3, 4}, {5, 6});
cout << concat (separator (","), pairs) << "\n";

I think you're trying to keep things simple, so perhaps this is a feature too far.

Bklyn avatar Jul 30 '14 22:07 Bklyn

I think it wouldn't be so hard to overload the separator function to accept parameters that may specify this kind of delimiters for sequences, even depending of the type. Looks fun. But it certainly would complicate the code, and as you have guessed, I'm trying to have this correct and simple, and my goal wasn't to make an encoder. Maybe I take the time to play with the possibility in another separated header.

In the meantime, if you need this for your projects: Just modify the code, and hardcode the delimiters in the appropriate base cases. That would be easy and fast.

Thanks for sharing the idea.

theypsilon avatar Jul 31 '14 15:07 theypsilon

@Bklyn I implemented your proposal in a branch: https://github.com/theypsilon/concat/tree/container_separator

I'm still considering if I should merge it to master or not. I removed some undocumented features too and it makes 319 lines now. But I'm not so happy with the lack of flexibility of the new separator interface.

Please, take a look when you have time, and tell me your impressions.

theypsilon avatar Aug 05 '14 16:08 theypsilon