W
woodbrian77
I'd like to see stream constructors like this added to
container classes.
#ifdef CMW_DREAMER
#include <ReceiveBuffer.hh>
#endif
template < ...>
class container {
...
#ifdef CMW_DREAMER
template <class R>
explicit container
:cmw::ReceiveBuffer<R>& buf)
{
int32_t count=buf.template Give<uint32_t>();
for(; count>0; --count)
emplace_back(value_type{buf});
}
#endif
};
If the value_type was numeric, one line would have
to change:
emplace_back(buf.template Give<value_type>());
How to integrate those two things?
Having stream constructors would help me get
away from outputting code like this:
template <class R>
void Give
:cmw::ReceiveBuffer<R>& buf
,std::vector<std::deque<std::string> >& az1){
int32_t count[2];
count[0]=buf.template Give<uint32_t>();
az1.reserve(az1.size()+count[0]);
for(;count[0]>0;--count[0]){
std::deque<std::string> rep2;
count[1]=buf.template Give<uint32_t>();
for(;count[1]>0;--count[1]){
rep2.emplace_back(buf.GiveString());
}
az1.emplace_back
:std::move(rep2));
}
}
And toward code like this:
template <class R>
void Give
:cmw::ReceiveBuffer<R>& buf
,std::vector<std::deque<std::string> >& az1){
std::vector<std::deque<std::string> >{buf}.swap(az1);
}
I realize the semantics are different between those
two, but am not sure it matters.
Would Leigh humor me by adding something like this
to segmented_array? Tia.
Brian
Ebenezer Enterprises
http://webEbenezer.net
container classes.
#ifdef CMW_DREAMER
#include <ReceiveBuffer.hh>
#endif
template < ...>
class container {
...
#ifdef CMW_DREAMER
template <class R>
explicit container
{
int32_t count=buf.template Give<uint32_t>();
for(; count>0; --count)
emplace_back(value_type{buf});
}
#endif
};
If the value_type was numeric, one line would have
to change:
emplace_back(buf.template Give<value_type>());
How to integrate those two things?
Having stream constructors would help me get
away from outputting code like this:
template <class R>
void Give
,std::vector<std::deque<std::string> >& az1){
int32_t count[2];
count[0]=buf.template Give<uint32_t>();
az1.reserve(az1.size()+count[0]);
for(;count[0]>0;--count[0]){
std::deque<std::string> rep2;
count[1]=buf.template Give<uint32_t>();
for(;count[1]>0;--count[1]){
rep2.emplace_back(buf.GiveString());
}
az1.emplace_back
}
}
And toward code like this:
template <class R>
void Give
,std::vector<std::deque<std::string> >& az1){
std::vector<std::deque<std::string> >{buf}.swap(az1);
}
I realize the semantics are different between those
two, but am not sure it matters.
Would Leigh humor me by adding something like this
to segmented_array? Tia.
Brian
Ebenezer Enterprises
http://webEbenezer.net