Index: boost/format/format_class.hpp =================================================================== --- boost/format/format_class.hpp (revision 51826) +++ boost/format/format_class.hpp (working copy) @@ -50,12 +50,22 @@ #endif io::detail::locale_t getloc() const; + // The total number of arguments expected to be passed to the format string. + int expected_args() const + { return num_args_; } + // The number of arguments currently bound to the format string. + int bound_args() const + { return cur_arg_; } + // The number of arguments still required to be passed to the format string. + int remaining_args() const + { return expected_args() - bound_args(); } + basic_format& clear(); // empty all converted string buffers (except bound items) basic_format& clear_binds(); // unbind all bound items, and call clear() basic_format& parse(const string_type&); // resets buffers and parse a new format string // ** formatted result ** // - size_type size() const; // sum of the current string pieces sizes + size_type size() const; // The number of characters in the formatted result string. string_type str() const; // final string // ** arguments passing ** // @@ -127,7 +137,7 @@ std::vector items_; // each '%..' directive leads to a format_item std::vector bound_; // stores which arguments were bound. size() == 0 || num_args - int style_; // style of format-string : positional or not, etc + int style_; // style of format-string : positional or not, etc int cur_arg_; // keep track of wich argument is current int num_args_; // number of expected arguments mutable bool dumped_; // true only after call to str() or << Index: libs/format/test/format_test3.cpp =================================================================== --- libs/format/test/format_test3.cpp (revision 51826) +++ libs/format/test/format_test3.cpp (working copy) @@ -93,6 +93,31 @@ BOOST_ERROR("nesting did not work"); } + // observers + BOOST_CHECK_EQUAL(format("foo").expected_args(), 0); + BOOST_CHECK_EQUAL(format("foo").bound_args(), 0); + BOOST_CHECK_EQUAL(format("foo").remaining_args(), 0); + + BOOST_CHECK_EQUAL(format("foo%s").expected_args(), 1); + BOOST_CHECK_EQUAL(format("foo%s").bound_args(), 0); + BOOST_CHECK_EQUAL(format("foo%s").remaining_args(), 1); + + BOOST_CHECK_EQUAL((format("foo%s") % "bar").expected_args(), 1); + BOOST_CHECK_EQUAL((format("foo%s") % "bar").bound_args(), 1); + BOOST_CHECK_EQUAL((format("foo%s") % "bar").remaining_args(), 0); + + BOOST_CHECK_EQUAL((format("%2%%1%") % "bar" % "foo").expected_args(), 2); + BOOST_CHECK_EQUAL((format("%2%%1%") % "bar" % "foo").bound_args(), 2); + BOOST_CHECK_EQUAL((format("%2%%1%") % "bar" % "foo").remaining_args(), 0); + + BOOST_CHECK_EQUAL((format("%1$s %2$s %1$s") % "bar").expected_args(), 2); + BOOST_CHECK_EQUAL((format("%1$s %2$s %1$s") % "bar").bound_args(), 1); + BOOST_CHECK_EQUAL((format("%1$s %2$s %1$s") % "bar").remaining_args(), 1); + + BOOST_CHECK_EQUAL((format("%1%, %2%, %|40t|%3%\n") % "foo" % "bar").expected_args(), 3); + BOOST_CHECK_EQUAL((format("%1%, %2%, %|40t|%3%\n") % "foo" % "bar").bound_args(), 2); + BOOST_CHECK_EQUAL((format("%1%, %2%, %|40t|%3%\n") % "foo" % "bar").remaining_args(), 1); + // testcase for bug reported at // http://lists.boost.org/boost-users/2006/05/19723.php format f("%40t%1%");