[xijiajia]transform map value to file

看了一个电影,叫<<剑雨>>,有一句台词,在此记录。spa

“佛陀弟子阿难出家前在道上遇一少女,今后爱慕难舍。佛祖问他,“你有多爱那少女 ”?阿难说:“我愿化成石桥,受五百年风吹,五百年雨打,五百年日晒,但求此少女从桥上走过”code

 写了一段代码,在此记录。orm


-------排版·分隔符-------get

//Given an STL (key,value) pairs, selected2nd returnstring

//extract the second part of a pairit

template<typename P>
struct selected2nd {
  typename P::second_type operator()(const P& p) const {
    return  p.second; 
  }
};

//A utility template function to make the use of select2nd easy.
//Pass an STL container consisting of (key, value) pairs and it
//automatically creates a select2nd that utilizes the
//value type. This works nicely as the template functions can deduce the
//template parameters based on the function parameters. 
template<typename C> 
selected2nd<typename C::value_type > make_select2nd( const C& container ) { 
  return selected2nd<typename C::value_type >(); 
}io


-------排版·分隔符-------ast

 

operator std::string() const{
std::stringstream sstr;
sstr<<"Vertex"<<" "
<<id<<" "<<coords.getX()<<" "
<<coords.getY()<<" "
<<coords.getZ()<<" "
<<"{normal("
<<normal.getX()<<" "
<<normal.getY()<<" "
<<normal.getZ()<<")}";
return sstr.str();
}
friend std::ostream& operator<<(std::ostream& out,dcel_vertex const* v){
out<<static_cast<string>(*v);
return out;
}

 

-------排版·分隔符-------function

 

void dcel_solid::save_to_m_file(string fileName){
std::ofstream fout(fileName);

//export the vertexs information
std::transform(
vertexs.begin(),vertexs.end(),
ostream_iterator(fout,"\n"),
make_select2nd(vertexs));

//write a blank line
fout<
//export the face information
std::transform(
faces.begin(),faces.end(),
ostream_iterator(fout,"\n"),
make_select2nd(faces));
}

 

-------排版·分隔符-------form

感受,这样的代码比较符合STL的风格,可是有不少代码没办法写的这样优雅,老是一个for套一个for,应该能够被重构成此类代码,要从新组织逻辑。 

相关文章
相关标签/搜索