View Single Post
Old Jul 23rd, 2005, 7:21 PM   #7
Shapeless
Programmer
 
Shapeless's Avatar
 
Join Date: Jul 2005
Location: germany/hamburg
Posts: 32
Rep Power: 0 Shapeless is on a distinguished road
Send a message via ICQ to Shapeless Send a message via MSN to Shapeless
I would say boost/algorithm/string/split.hpp is what u need. its still no standart functions , but a lot of the boost libs will become standart in the 0x10 c++ standart and i m pretty sure that the string-algo lib will...
btw boost is so powerfull u should have a look or even learn to handle some parts.

like boost::split
the function gets a sequence,a collection and a prdicate, and an so called token compress mode type, but u dont need that one.
so for your purposes it would look like this

template<typename SequenceSequenceT, typename CollectionT, 
             typename PredicateT> 
      SequenceSequenceT & 
      split(SequenceSequenceT &, CollectionT &, PredicateT, 
            token_compress_mode_type = token_compress_off);
or shorter:
      split(SequenceSequenceT &, CollectionT &, PredicateT);
where for example the collections is a std::string and the sequence is a std::vector<std::string>
id just wrote this little testmain. i think its exactly what you ask for:
#include<iostream>
#include<string>
#include<vector>
#include<boost/algorithm/string.hpp>

#include<algorithm>//test output
#include<iterator>// test output


int main() {
	std::string line("hallo-this-is-a-string");
	std::vector<std::string> result;
	boost::split(result,line,boost::is_any_of("-"));
                       // puts the result of a split of line into the 
                       // result container without things that match to the prediate
                       //"-" or in your case " "
	if(!result.empty())
		std::copy(result.begin(),result.end(),std::ostream_iterator<std::string>(std::cout,"\n"));
	return 0;
}
so here is the compare:
your wish:
function(container,string,delim);
solution:
split(container,string,predicate); where predicate is the delim...
as you can see its exactly the same u ask for. but since it is a template u
can use it on every containers convertable to each other.
__________________
of all the things he has lost, i think he misses his mind the most

typedef typename pizza_t<oven_policy<225,12.5>,ingredient_policy<salami,mushroom,cheese> > Pizza;
Shapeless is offline   Reply With Quote