// -*- C++ -*-
//  Boost general library 'format'  ---------------------------
//  See http://www.boost.org for updates, documentation, and revision history.

//  (C) Samuel Krempp 2001
//                  krempp@crans.ens-cachan.fr
//  Permission to copy, use, modify, sell and
//  distribute this software is granted provided this copyright notice appears
//  in all copies. This software is provided "as is" without express or implied
//  warranty, and with no claim as to its suitability for any purpose.

// ----------------------------------------------------------------------------
// sample_new_features.cpp : printf の文法に追加された機能を実演する
// ----------------------------------------------------------------------------

#include <iostream>
#include <iomanip>

#include "boost/format.hpp"

int main(){
    using namespace std;
    using boost::format;
    using boost::io::group;
    using boost::io::str;
    stringstream oss;

    // ------------------------------------------------------------------------
    // 並べ替えの単純な形式 :
    cout << format("%1% %2% %3% %2% %1% \n") % "o" % "oo" % "O";
    //          "o oo O oo o \n" と表示する


    // ------------------------------------------------------------------------
    // 中寄せ : '=' フラグ
    cout << format("_%|=6|_") % 1 << endl;
    //          "_   1  _" と表示する : 三つの空白が前に、二つが後ろにパディングされる。



    // ------------------------------------------------------------------------
    // 桁送り      :   "%|Nt|"  => 空白 N 個の桁送り。
    //                 "%|NTf|" => 文字 <f> を N 回分だけ桁送り。
    //  幅が大きく変わり得るフィールドがいくつもあるような行で、可能ならば
    //    いくつかは同じ場所に出力したいようなとき、便利である :
    vector<string>  names(1, "Marc-Fran輟is Michel"), 
      surname(1,"Durand"), 
      tel(1, "+33 (0) 123 456 789");

    names.push_back("Jean"); 
    surname.push_back("de Lattre de Tassigny");
    tel.push_back("+33 (0) 987 654 321");

    for(unsigned int i=0; i<names.size(); ++i)
      cout << format("%1%, %2%, %|40t|%3%\n") % names[i] % surname[i] % tel[i];

    /* 次のように表示する :

       
    Marc-Franc,is Michel, Durand,       +33 (0) 123 456 789
    Jean, de Lattre de Tassigny,        +33 (0) 987 654 321
    
    
     the same using width on each field lead to unnecessary too long lines,
     while 'Tabulations' insure a lower bound on the *sum* of widths,
     and that's often what we really want.
     それぞれのフィールドで同じ幅を使おうとすると必要以上に行が長くなりすぎることがあるが、
     '桁送り' は幅の *和* を下限に抑えるよう保証する。
     そして我々がしばしば本当に必要とするのはそういう動作である。
    */



    cerr << "\n\nEverything went OK, exiting. \n";
    return 0;
}

