基本的に double のベクトルから値を読み取り、これらを文字列に追加して (それぞれの間にスペースを確保し、精度を設定しながら)、最終結果から最終的な空白を差し引いたものを返す関数があります。
std::string MultiplePrintProperties::GetHpitchString()
{
std::string str;
vector< double >::iterator it;
for ( it = Vals.begin();
it != Vals.end();
it++ )
{
ostringstream s;
// Set precision to 3 digits after the decimal point
// and read into the string
boost::format fmt( "%.3f " );
s << fmt % *( it );
str.append( s.str() );
}
// Remove last white space and return string
return str.substr( 0, str.length() - 1 );
}
このコードを何らかの方法で単純化できるかどうかを調べたいと思います。私は最近、特に for_each とファンクターの使用を調査していますが、これらの手法がこの特定の例をどのように改善できるかを理解できていません。