diff --git a/doc/00_main.qbk b/doc/00_main.qbk index 81af79f..38898d7 100644 --- a/doc/00_main.qbk +++ b/doc/00_main.qbk @@ -34,7 +34,9 @@ [include type_requirements.qbk] [include performance.qbk] [include other.qbk] +[include design_notes.qbk] [include acknowledgments.qbk] [include references.qbk] [include 98_ref.qbk] [include 99_index.qbk] + diff --git a/doc/12_facade_api.qbk b/doc/12_facade_api.qbk deleted file mode 100644 index 82ef9b6..0000000 --- a/doc/12_facade_api.qbk +++ /dev/null @@ -1,13 +0,0 @@ -[section Ode to Component Design] - -When looked at the ['boost::convert()] in isolation the facade API does very little on its own. Still, it is an important artefact of the component design. The component (software and industrial) design is essential for any system of reasonable size and longevity. - -Its distinctive quality is that it is driven by interfaces, "connectors". Those allow varying components to be plugged-in together and to communicate in order to work in cooperation. - -In the component design known behavior and familiar/compatible interfaces are important and are the characteristics that allow many different pieces/components to work in cooperation and to form a system. - -Statistically any serious software system (of reasonable size and longevity) spends eighty percent (meaning it is really important) of its total time in the maintenance phase with software entropy or complexity increasing over time. The component design is the only - -It allows chanto plug an electrical device into an electric wall socket without even thinking about. Ttrying it in a different country might be a very frustrating and often impossible excersice. - - diff --git a/doc/convert_ref.xml b/doc/convert_ref.xml index 096c8fe..8c6a5ca 100644 --- a/doc/convert_ref.xml +++ b/doc/convert_ref.xml @@ -1,15 +1,10 @@ -Convert Reference
boost::conversion::result< TypeOut >FallbackType const &TypeOut const &this_type &bool
diff --git a/doc/design_notes.qbk b/doc/design_notes.qbk new file mode 100644 index 0000000..27ced56 --- /dev/null +++ b/doc/design_notes.qbk @@ -0,0 +1,19 @@ +[section Design Notes] +[section Requirements] + +['Boost.Convert] has been designed to satisfy the following user requirements: + +# Provide fully-functional interfaces for two different program flows where + # error-processing is orthogonal to the normal program flow (exception-throwing interface); + # normal and error-processing flows are part of the same program flow (non-throwing interface); +# The throwing interface returns the result or throws an exception; +# The non-throwing interface returns the result and/or some indication of conversion success or failure; + # the result is only available in the case of conversion success; + # in the case of failure an attempt to retrieve the result (with no default provided) results in an exception thrown; + # in the case of failure an optional default value can be supplied instead; +# Converters are independent and do not rely on the ['Boost.Convert] framework. + +[endsect] +[endsect] + + diff --git a/doc/generate-html.sh b/doc/generate-html.sh index 70e0fc6..70e2a7f 100755 --- a/doc/generate-html.sh +++ b/doc/generate-html.sh @@ -1,5 +1,5 @@ export BOOST_ROOT=$HOME/dev/boost_1_55_0 -bjam --toolset=gcc --enable-index +$BOOST_ROOT/bjam --toolset=gcc --enable-index #bjam --toolset=gcc --enable-index pdf diff --git a/doc/html/boost/conversion/result.html b/doc/html/boost/conversion/result.html index d92476e..8124edb 100644 --- a/doc/html/boost/conversion/result.html +++ b/doc/html/boost/conversion/result.html @@ -7,11 +7,11 @@ - +
-PrevUpHomeNext +PrevUpHomeNext
@@ -26,46 +26,44 @@ struct result { // types typedef result this_type; - typedef unspecified out_type; typedef boost::safebool< result > safebool; // construct/copy/destruct - result(out_type const &); + result(TypeOut const &); - // public member functions - bool operator!() const; - operator typename safebool::type() const; - out_type const & value() const; - template<typename FallbackType> - out_type value_or(FallbackType const &) const; + // public member functions + bool operator!() const; + operator typename safebool::type() const; + TypeOut const & value() const; + template<typename FallbackType> TypeOut value_or(FallbackType const &) const; - // private member functions - this_type & operator()(bool); + // private member functions + this_type & operator()(bool); };
-

Description

+

Description

-

+

result public construct/copy/destruct

-
  1. result(out_type const & v);
+
  1. result(TypeOut const & v);
-

-result public member functions

+

+result public member functions

    -
  1. bool operator!() const;
  2. -
  3. operator typename safebool::type() const;
  4. -
  5. out_type const & value() const;
  6. +
  7. bool operator!() const;
  8. +
  9. operator typename safebool::type() const;
  10. +
  11. TypeOut const & value() const;
  12. template<typename FallbackType> 
    -  out_type value_or(FallbackType const & fallback) const;
  13. + TypeOut value_or(FallbackType const & fallback) const;
-

-result private member functions

-
  1. this_type & operator()(bool good);
+

+result private member functions

+
  1. this_type & operator()(bool good);
@@ -78,7 +76,7 @@
-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/convert_reference.html b/doc/html/convert_reference.html index 1b82ce7..d982d3b 100644 --- a/doc/html/convert_reference.html +++ b/doc/html/convert_reference.html @@ -7,18 +7,17 @@ - +
-PrevUpHomeNext +PrevUpHomeNext

Convert Reference

-
Header <boost/convert/api.hpp>
-
Header <boost/convert/forward.hpp>
+
Header <boost/convert/forward.hpp>
Header <boost/convert/parameters.hpp>
Header <boost/convert/result.hpp>
@@ -26,14 +25,13 @@
+Header <boost/convert/forward.hpp>
namespace boost {
   template<typename TypeOut, typename TypeIn, typename Converter> 
     boost::conversion::result< TypeOut > 
-    convert(TypeIn const & value_in, Converter const & converter);
-  template<typename TypeOut, typename Converter> 
-    boost::conversion::algorithm_helper< TypeOut, Converter > 
-    convert(Converter const & cnv);
+    convert(TypeIn const &, Converter const &);
+  namespace conversion {
+  }
 }
@@ -46,7 +44,7 @@
-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/header/boost/convert/forward_hpp.html b/doc/html/header/boost/convert/forward_hpp.html deleted file mode 100644 index a38c61f..0000000 --- a/doc/html/header/boost/convert/forward_hpp.html +++ /dev/null @@ -1,37 +0,0 @@ - - - -Header <boost/convert/forward.hpp> - - - - - - - - -
-PrevUpHomeNext -
-
-

-Header <boost/convert/forward.hpp>

-
namespace boost {
-  template<typename T> T allocate_storage();
-  namespace conversion {
-  }
-}
-
- - - -
-
-
-PrevUpHomeNext -
- - diff --git a/doc/html/header/boost/convert/parameters_hpp.html b/doc/html/header/boost/convert/parameters_hpp.html index d52ee19..e775a3f 100644 --- a/doc/html/header/boost/convert/parameters_hpp.html +++ b/doc/html/header/boost/convert/parameters_hpp.html @@ -6,12 +6,12 @@ - +
-PrevUpHomeNext +PrevUpHomeNext

@@ -21,11 +21,11 @@ struct base; struct notation; namespace parameter { - BOOST_PARAMETER_KEYWORD(type, base); - BOOST_PARAMETER_KEYWORD(type, locale); - BOOST_PARAMETER_KEYWORD(type, precision); - BOOST_PARAMETER_KEYWORD(type, uppercase); - BOOST_PARAMETER_KEYWORD(type, notation); + BOOST_PARAMETER_KEYWORD(type, base); + BOOST_PARAMETER_KEYWORD(type, locale); + BOOST_PARAMETER_KEYWORD(type, precision); + BOOST_PARAMETER_KEYWORD(type, uppercase); + BOOST_PARAMETER_KEYWORD(type, notation); } } } @@ -39,7 +39,7 @@
-PrevUpHomeNext +PrevUpHomeNext
diff --git a/doc/html/index.html b/doc/html/index.html index 1ead8fe..02384ea 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -50,18 +50,19 @@ Default Constructible Type Requirement
Performance
Other Conversions
+
Design Notes
+
Requirements
Acknowledgements
References
Convert Reference
-
Header <boost/convert/api.hpp>
-
Header <boost/convert/forward.hpp>
+
Header <boost/convert/forward.hpp>
Header <boost/convert/parameters.hpp>
Header <boost/convert/result.hpp>
-
Index
+
Index

@@ -101,9 +102,9 @@ requirements (namely, Default Constructibility);
  • - a failure to read and to convert a user-provided configuration parameter - was not that rare or exceptional to justify the hassle and the overhead - of exception processing; + failure to convert a user-provided configuration parameter was not that + rare or exceptional to justify the hassle and the overhead of exception + processing;
  • additional flexibility (if, when @@ -122,13 +123,13 @@ the requested extensions were not compatible with the original design and the idea of what boost::lexical_cast embodied and, therefore, a new component with richer interface and functionality was needed. That decision - resulted in the development and the subsequent submission of the Boost.Convert - library described in this document. + resulted in the development of Boost.Convert described + in this document.

  • - +

    Last revised: May 20, 2014 at 23:11:49 GMT

    Last revised: June 03, 2014 at 02:02:54 GMT


    diff --git a/doc/html/index/s16.html b/doc/html/index/s17.html similarity index 57% rename from doc/html/index/s16.html rename to doc/html/index/s17.html index 87e8e2e..edfc0d4 100644 --- a/doc/html/index/s16.html +++ b/doc/html/index/s17.html @@ -14,24 +14,9 @@

    -Index

    -

    O S

    -
    -
    -O -
    -
    -
    -S -
    -
    -
    +Index
    +

    +
    diff --git a/doc/html/standalone_HTML.manifest b/doc/html/standalone_HTML.manifest index 4b1ee6a..278655d 100644 --- a/doc/html/standalone_HTML.manifest +++ b/doc/html/standalone_HTML.manifest @@ -12,13 +12,13 @@ the_boost_convert_library/type_requirements.html the_boost_convert_library/the___default_constructible__type_requirement.html the_boost_convert_library/performance.html the_boost_convert_library/other_conversions.html +the_boost_convert_library/design_notes.html the_boost_convert_library/acknowledgements.html the_boost_convert_library/references.html convert_reference.html -header/boost/convert/forward_hpp.html header/boost/convert/parameters_hpp.html boost/conversion/base.html boost/conversion/notation.html header/boost/convert/result_hpp.html boost/conversion/result.html -index/s16.html +index/s17.html diff --git a/doc/html/the_boost_convert_library/acknowledgements.html b/doc/html/the_boost_convert_library/acknowledgements.html index 29795f2..aa58870 100644 --- a/doc/html/the_boost_convert_library/acknowledgements.html +++ b/doc/html/the_boost_convert_library/acknowledgements.html @@ -6,12 +6,12 @@ - +
    -PrevUpHomeNext +PrevUpHomeNext

    @@ -49,7 +49,7 @@


    -PrevUpHomeNext +PrevUpHomeNext
    diff --git a/doc/html/the_boost_convert_library/design_notes.html b/doc/html/the_boost_convert_library/design_notes.html new file mode 100644 index 0000000..3cf693b --- /dev/null +++ b/doc/html/the_boost_convert_library/design_notes.html @@ -0,0 +1,82 @@ + + + +Design Notes + + + + + + + + +
    +PrevUpHomeNext +
    +
    +

    +Design Notes +

    +
    Requirements
    +
    + +

    + Boost.Convert has been designed to satisfy the following + user requirements: +

    +
      +
    1. + Provide fully-functional interfaces for two different program flows where +
        +
      1. + error-processing is orthogonal to the normal program flow (exception-throwing + interface); +
      2. +
      3. + normal and error-processing flows are part of the same program + flow (non-throwing interface); +
      4. +
      +
    2. +
    3. + The throwing interface returns the result or throws an exception; +
    4. +
    5. + The non-throwing interface returns the result and/or some indication + of conversion success or failure; +
        +
      1. + the result is only available in the case of conversion success; +
      2. +
      3. + in the case of failure an attempt to retrieve the result (with + no default provided) results in an exception thrown; +
      4. +
      5. + in the case of failure an optional default value can be supplied + instead; +
      6. +
      +
    6. +
    7. + Converters are independent and do not rely on the Boost.Convert + framework. +
    8. +
    +
    +
    + + + +
    +
    +
    +PrevUpHomeNext +
    + + diff --git a/doc/html/the_boost_convert_library/design_notes/why__boost__convert___.html b/doc/html/the_boost_convert_library/design_notes/why__boost__convert___.html new file mode 100644 index 0000000..0e6fbdc --- /dev/null +++ b/doc/html/the_boost_convert_library/design_notes/why__boost__convert___.html @@ -0,0 +1,120 @@ + + + +Why boost::convert() + + + + + + + +
    +PrevUpHome +
    +
    +

    +Why + boost::convert() +

    +

    + It does not take long to realize that boost::convert() by itself does very little. The respective + converter -- the worker component -- provides the actual + functionality and even a somewhat useable interface that can be deployed + directly (if one is determined to do so). I readily concede that on the one-man-project + level the existence of boost::convert() can be hardly justified. +

    +

    + boost::convert() + is the manager component and the benefits of deploying + varying conversion facilities via one consistent interface become clearer + on a larger industrial level of software development. +

    +

    + The purpose of boost::convert() + is to formalize, advertize and enforce a contract between + the user (service consumer) and the developer (service provider). +

    +

    + That ultimately minimizes dependency of the application-domain (user) code + on any particular infrastructure (conversion) API. New converters can be + introduced and deployed later in the development cycle, with minimal or no + impact on the existing code base as long as those converters conform to that + specified contract. +

    +

    + Based on that contract the consumer knows what to expect and the provider + knows what to provide without consumer-provider interaction. + In practical terms it is that every time I browse somebody else's code and + see the interface, I immediately know what it does without reading the docs, + learning new api, etc. In real life, when one is reading (trying to fix) + somebody else's code the "reading the docs, learning new api" seems + like a considerable diversion and often does not happen. So, the understanding + of the code quickly turns into a guessing game. So, productivity is no more. +

    +

    + More so, in my view there is no even Convert "library". :-) I see + my proposal as a conversion/transformation framework. + The difference between a library and a framework (in my view and in this + particular case, anyway) is that the latter is merely the guidelines how + to be able to develop code later that is + to be deployed in and without disrupting the old/existing code. That's what + convert::from API facade does. +

    +
    That allows the user to write his domain-specific code
    +
    +
    +

    + As you correctly pointed out one-particular-converter functionality can be + called directly rather than via "meaningless" convert::from. +

    +

    + The existence of Convert API facade is more for the purposes of managing a large development which includes simultaneously writing components which are meant + to interact or rely on each other; adjusting to requirement changes without + major existing code disruption (that includes major re-writes, major re-testing, + etc.). +

    +

    + Yes, I understand your reasoning. I personally find the pluggability quality + to be quite important. +

    +

    + First, from the first submission review it was clear to me that not everyone + was interested in the std::sstream-based functionality and prepared to accept + relative slowness of std::sstream. The pluggability addresses that issue + with minimal effort and makes the library useful for much wider programming + community. +

    +

    + Secondly, the separation of the API/facade from the actual converter -- the + pluggability -- allows to write and deploy new/better/domain-specific converters + easily -- as long as those converters conform to the API-imposed contract. + The difference in "plugging a new converter" vs "replacing + an existing directly-used converter with a new converter" is considerable + in a large-scale development as the former only replaces a pluggable component + (leaving the "plumbing" intact) and the latter may create a lot + of ripples in the related code. An every-day example might be unplugging + and replacing an electrical device. Clearly, with no pluggability replacing + such a device (directly connected to your house wiring) might be quite a + hassle. Yes, on one-person-writing-new-code level that pluggability looks + like a hassle. My argument is that on the large-code-base, maintenance, changed-requirements + phase pluggability is the only sane way to manage that change. +

    +
    + + + +
    +
    +
    +PrevUpHome +
    + + diff --git a/doc/html/the_boost_convert_library/introduction.html b/doc/html/the_boost_convert_library/introduction.html index 4d231d2..d607a61 100644 --- a/doc/html/the_boost_convert_library/introduction.html +++ b/doc/html/the_boost_convert_library/introduction.html @@ -125,16 +125,27 @@ textual hexadecimal representation and assigns INT_MAX to those which fail to convert:

    +

    +

    boost::array<char const*, 5> strings = {{ "0XF", "0X10", "0X11", "0X12", "not an int" }};
     std::vector<int>            integers;
     boost::cstringstream_converter   cnv; // stringstream-based char converter
     
     std::transform(
    -   strings.begin(),
    -   strings.end(),
    -   std::back_inserter(integers),
    -   convert<int>(cnv(std::hex)).value_or(INT_MAX));
    +    strings.begin(),
    +    strings.end(),
    +    std::back_inserter(integers),
    +    boost::convert<int>(cnv(std::hex)).value_or(INT_MAX));
    +
    +BOOST_TEST(integers.size() == 5);
    +BOOST_TEST(integers[0] == 15);
    +BOOST_TEST(integers[1] == 16);
    +BOOST_TEST(integers[2] == 17);
    +BOOST_TEST(integers[3] == 18);
    +BOOST_TEST(integers[4] == INT_MAX); // Failed conversion
     
    +

    +

    An interesting (and yet to be explored) property is that Boost.Convert is not limited to string-to-type and type-to-string conversions. The Boost.Convert diff --git a/doc/html/the_boost_convert_library/other_conversions.html b/doc/html/the_boost_convert_library/other_conversions.html index 43e19fe..7fc80ef 100644 --- a/doc/html/the_boost_convert_library/other_conversions.html +++ b/doc/html/the_boost_convert_library/other_conversions.html @@ -7,11 +7,11 @@ - +

    -PrevUpHomeNext +PrevUpHomeNext

    @@ -58,7 +58,7 @@
    -PrevUpHomeNext +PrevUpHomeNext
    diff --git a/doc/html/the_boost_convert_library/performance.html b/doc/html/the_boost_convert_library/performance.html index 3a7693e..3cf50fd 100644 --- a/doc/html/the_boost_convert_library/performance.html +++ b/doc/html/the_boost_convert_library/performance.html @@ -37,14 +37,15 @@ tests produced the following results:

    g++ -O0 test_convert.cpp <--- NON-OPTIMIZED
    -str-to-int: strtol/scanf/lcast/sstream=0.49/1.40/1.56/2.00 seconds.
    +str-to-int: strtol/scanf/lcast/sstream=0.49/1.40/1.56/1.77 seconds.
     int-to-str: ltostr/prntf/lcast/sstream=3.10/2.62/2.42/2.52 seconds.
     str-to-user-type: lcast/sstream=4.94/3.19 seconds.
     
     g++ -O3 test_convert.cpp <--- OPTIMIZED
    -str-to-int: strtol/scanf/lcast/sstream=0.28/1.15/0.45/1.70 seconds.
    +str-to-int: strtol/scanf/lcast/sstream=0.28/1.15/0.45/1.23 seconds.
     int-to-str: ltostr/prntf/lcast/sstream=1.50/2.17/1.11/1.73 seconds.
    -str-to-user-type: lcast/sstream=3.26/2.58 seconds.
    +str-to-user-type: lcast/sstream=3.58/1.99 seconds.
    +user-type-to-str: lcast/sstream=5.22/1.32 seconds.
     
    @@ -57,18 +58,26 @@ Optimized times are the ones to be looked at and analyzed.

    +
    boost.convert/test >> uname -a
    +Linux 3.13.0-24-generic #47-Ubuntu SMP ... i686 GNU/Linux
    +boost.convert/test >> g++ -O3 *.cpp -I../include -I../../boost_1_55_0
    +str-to-int: strtol/scanf/lcast/sstream=2.39/9.52/3.97/9.56 seconds.
    +int-to-str: ltostr/prntf/lcast/sstream=7.51/13.65/8.91/13.37 seconds.
    +str-to-user-type: lcast/sstream=27.46/13.97 seconds.
    +user-type-to-str: lcast/sstream=52.87/11.07 seconds.
    +

    On the Cygwin platform compiled with gcc 4.8.2:

    g++ -O3 test_convert.cpp
    -str-to-int: strtol/scanf/lcast/sstream=0.28/1.20/1.22/2.42 seconds.
    +str-to-int: strtol/scanf/lcast/sstream=0.28/1.20/1.22/1.82 seconds.
     int-to-str: ltostr/prntf/lcast/sstream=1.31/2.94/2.62/2.03 seconds.
     str-to-user-type: lcast/sstream=7.44/4.61 seconds.
     

    Compiled with MS Visual C++ 2010 Express optimized for speed:

    -
    str-to-int: strtol/scanf/lcast/sstream=0.28/0.89/1.03/6.20 seconds.
    +
    str-to-int: strtol/scanf/lcast/sstream=0.28/0.89/1.03/4.65 seconds.
     int-to-str: ltostr/prntf/lcast/sstream=1.11/1.86/1.91/5.92 seconds.
     str-to-user-type: lcast/sstream=6.81/3.30 seconds.
     
    diff --git a/doc/index.idx b/doc/index.idx index b6d020a..be63d5e 100644 --- a/doc/index.idx +++ b/doc/index.idx @@ -1,2 +1,2 @@ -!scan ../include/boost/convert/api.hpp +!scan ../include/boost/convert.hpp diff --git a/doc/introduction.qbk b/doc/introduction.qbk index c063d61..494e242 100644 --- a/doc/introduction.qbk +++ b/doc/introduction.qbk @@ -36,17 +36,9 @@ The `std::stringstream`-based converter draws on the standard `std::streams` fun * support for different locales; * `char` and `wchar_t` support. -For example, the following snippet converts an array of integers from their textual hexadecimal representation and assigns INT_MAX to those which fail to convert: +[import ../test/algorithms.cpp] - boost::array strings = {{ "0XF", "0X10", "0X11", "0X12", "not an int" }}; - std::vector integers; - boost::cstringstream_converter cnv; // stringstream-based char converter - - std::transform( - strings.begin(), - strings.end(), - std::back_inserter(integers), - convert(cnv(std::hex)).value_or(INT_MAX)); +[algorithm_simple] An interesting (and yet to be explored) property is that ['Boost.Convert] is not limited to string-to-type and type-to-string conversions. The ['Boost.Convert] API facade is type-agnostic and the plugged-in converter ultimately dictates what types and conversions are supported. Consequently, a wide range of conversion\/transformation-related tasks can be addressed and deployed ['uniformly] by plugging-in special-purpose converters. diff --git a/doc/12_design_notes.qbk b/doc/scratchpad.txt similarity index 78% rename from doc/12_design_notes.qbk rename to doc/scratchpad.txt index e57aa35..897fb4b 100644 --- a/doc/12_design_notes.qbk +++ b/doc/scratchpad.txt @@ -1,5 +1,17 @@ -[section Design Notes] -[section Why `boost::convert()`] +[section Component Design] + +When looked at the ['boost::convert()] in isolation the facade API does very little on its own. Still, it is an important artefact of the component design. The component (software and industrial) design is essential for any system of reasonable size and longevity. + +Its distinctive quality is that it is driven by interfaces, "connectors". Those allow varying components to be plugged-in together and to communicate in order to work in cooperation. + +In the component design known behavior and familiar/compatible interfaces are important and are the characteristics that allow many different pieces/components to work in cooperation and to form a system. + +Statistically any serious software system (of reasonable size and longevity) spends eighty percent (meaning it is really important) of its total time in the maintenance phase with software entropy or complexity increasing over time. The component design is the only + +It allows chanto plug an electrical device into an electric wall socket without even thinking about. Ttrying it in a different country might be a very frustrating and often impossible excersice. + + + It does not take long to realize that `boost::convert()` by itself does very little. The respective converter -- the ['worker] component -- provides the actual functionality and even a somewhat useable interface that can be deployed directly (if one is determined to do so). I readily concede that on the one-man-project level the existence of `boost::convert()` can be hardly justified. @@ -66,6 +78,4 @@ argument is that on the large-code-base, maintenance, changed-requirements phase pluggability is the only sane way to manage that change. [endsect] -[endsect] - diff --git a/test/algorithms.cpp b/test/algorithms.cpp index 9627d9a..43d2f44 100644 --- a/test/algorithms.cpp +++ b/test/algorithms.cpp @@ -55,13 +55,42 @@ ints_to_strings() BOOST_TEST(strings[3] == "0X12"); } +static +void +strings_to_ints_simple() +{ +//[algorithm_simple + + /*`For example, the following snippet converts an array of integers from their textual hexadecimal + representation and assigns INT_MAX to those which fail to convert: + */ + + boost::array strings = {{ "0XF", "0X10", "0X11", "0X12", "not an int" }}; + std::vector integers; + boost::cstringstream_converter cnv; // stringstream-based char converter + + std::transform( + strings.begin(), + strings.end(), + std::back_inserter(integers), + boost::convert(cnv(std::hex)).value_or(INT_MAX)); + + BOOST_TEST(integers.size() == 5); + BOOST_TEST(integers[0] == 15); + BOOST_TEST(integers[1] == 16); + BOOST_TEST(integers[2] == 17); + BOOST_TEST(integers[3] == 18); + BOOST_TEST(integers[4] == INT_MAX); // Failed conversion +//] +} + static void strings_to_ints() { - boost::array strings = {{ "0XF", "0X10", "0X11", "0X12", "not int" }}; + boost::array strings = {{ "0XF", "0X10", "0X11", "0X12", "not an int" }}; std::vector integers; - boost::cstringstream_converter ccnv; // stringstream-based char converter + boost::cstringstream_converter cnv; // stringstream-based char converter //////////////////////////////////////////////////////////////////////////// // String to integer conversion. @@ -88,7 +117,7 @@ strings_to_ints() strings.begin(), strings.end(), std::back_inserter(integers), - boost::convert(ccnv(std::hex))); + boost::convert(cnv(std::hex))); BOOST_TEST(!"Failed to throw"); } @@ -104,22 +133,7 @@ strings_to_ints() integers.clear(); - //////////////////////////////////////////////////////////////////////////// - // String to integer conversion. Explicit fallback, i.e. no throwing. Hex formatting. - //////////////////////////////////////////////////////////////////////////// - - std::transform( - strings.begin(), - strings.end(), - std::back_inserter(integers), - boost::convert(ccnv(arg::base = cnv::base::hex)).value_or(-1)); - - BOOST_TEST(integers.size() == 5); - BOOST_TEST(integers[0] == 15); - BOOST_TEST(integers[1] == 16); - BOOST_TEST(integers[2] == 17); - BOOST_TEST(integers[3] == 18); - BOOST_TEST(integers[4] == -1); // Failed conversion + strings_to_ints_simple(); #ifdef NOT_AVAILABLE_UNTIL_CPP11 diff --git a/test/makefile b/test/makefile index 936e049..5a6098b 100644 --- a/test/makefile +++ b/test/makefile @@ -9,6 +9,6 @@ -all: $(wildcard *.cpp) +all: $(wildcard *.cpp) g++ *.cpp -I../include -I../../boost_1_55_0