Compare commits

..

172 Commits

Author SHA1 Message Date
Daniel James
6032348b4c Branch for working on the documentation tools documentation.
[SVN r68640]
2011-02-04 21:18:24 +00:00
Beman Dawes
3279399fe3 Remove BOOST_ENABLE_ASSERT_MSG_HANDLER; use BOOST_ENABLE_ASSERT_HANDLER in its stead
[SVN r68423]
2011-01-24 20:15:36 +00:00
Beman Dawes
87875cadda Add BOOST_ASSERT_MSG. Add macros to configure output stream.
[SVN r68414]
2011-01-24 15:37:13 +00:00
Daniel Walker
c58748cfd9 use declval to fix #5098
[SVN r68373]
2011-01-22 22:18:48 +00:00
Steven Watanabe
58bb88d4bd Revert [67111] (addition of boost/detail/iomanip.hpp) and all the commits that depend on it. ([68137], [68140], [68141], [68154], and [68165]).
[SVN r68168]
2011-01-15 08:11:51 +00:00
Bryce Adelstein-Lelbach
11d50ecb9f Replacing the use of <iomanip> with <boost/detail/iomanip.hpp> across Boost.
On Linux, GNU's libstdc++, which is the default stdlib for icc and clang,
cannot parse the <iomanip> header in version 4.5+ (which thankfully neither
compiler advises the use of yet), as it's original C++98-friendly
implementation has been replaced with a gnu++0x implementation.
<boost/detail/iomanip.hpp> is a portable implementation of <iomanip>, providing
boost::detail::setfill, boost::detail::setbase, boost::detail::setw,
boost::detail::setprecision, boost::detail::setiosflags and
boost::detail::resetiosflags. 



[SVN r68140]
2011-01-14 02:35:58 +00:00
Daniel Frey
636283d7c2 Limit warning suppression to old versions of VC++, fixes #4432
[SVN r67278]
2010-12-16 17:30:46 +00:00
Daniel James
1df0bf80bc Stop inspect complaining that assert is used in BOOST_ASSERT.
[SVN r66574]
2010-11-14 18:37:37 +00:00
John Maddock
71e78a0081 Add declval and common type from Vicente J. Botet Escriba.
Regenerate docs.

[SVN r65443]
2010-09-17 12:12:03 +00:00
Steven Watanabe
f7e4b0e399 Make sure that utility/index.html has a complete list of components. Fixes #4629.
[SVN r65437]
2010-09-16 15:40:47 +00:00
Daniel Walker
fb1d2effef correction to result_of documentation
[SVN r64696]
2010-08-09 16:23:50 +00:00
Daniel Walker
94b91e8c92 updated result_of documentation
[SVN r64695]
2010-08-09 16:07:20 +00:00
Daniel James
a4b8043e68 Fix some header links.
[SVN r64006]
2010-07-14 08:15:33 +00:00
Niels Dekker
b4a08fc80e Added test for private_int_array_pair, hoping to (possibly) fix a minion-clang/darwin-4.2.1 failure at boost.org/development/tests/trunk/developer/utility_.html
[SVN r63045]
2010-06-17 16:53:55 +00:00
Niels Dekker
9da96d9737 Added value_init_workaround_test, reviewed by Fernando Cacciola, see #3869
[SVN r63014]
2010-06-16 08:45:43 +00:00
Niels Dekker
a991936c96 Made memset call in value_init conditional, see #3869. Updated the section "compiler issues" of its documentation.
[SVN r62307]
2010-05-30 09:19:09 +00:00
Niels Dekker
6239e685a2 value_init_test now uses lightweight_test by Peter Dimov; see #4246. Fernando Cacciola mailed me he agreed as well.
[SVN r62158]
2010-05-22 22:05:54 +00:00
Niels Dekker
e601fcb9c9 Locally disabled a trivial MSVC warning in value_init.hpp (C4512, "assignment operator could not be generated")
[SVN r62030]
2010-05-16 11:08:00 +00:00
Niels Dekker
f29a5db08e Hopefully fixed value_initialized compile errors on clang and comeau (strict mode) reported by Christopher Jefferson, see #4213
[SVN r61947]
2010-05-13 14:36:06 +00:00
Niels Dekker
22743ee125 Added boost::initialized<T> as was agreed at http://lists.boost.org/Archives/boost/2010/04/164916.php -- see #3472
[SVN r61883]
2010-05-09 20:51:24 +00:00
Eric Niebler
e3c982287a add tr1_result_of that always behaves as TR1 specifies, fix Boost.TR1's result_of to use tr1_result_of
[SVN r61248]
2010-04-13 15:01:11 +00:00
Daniel James
82e1111bb8 Revert [60052], as it causes other libraries to break.
[SVN r61097]
2010-04-06 07:56:54 +00:00
Niels Dekker
9339b32178 Updated copyright notice.
[SVN r61075]
2010-04-05 19:08:01 +00:00
Niels Dekker
3770221507 Hopefully fixed #3984 (std::bitset constructor issue). Tested by Juergen Hunold on msvc-10.0, msvc-9.0, and gcc-4.4. See thread starting at http://lists.boost.org/Archives/boost/2010/03/162690.php
[SVN r60331]
2010-03-07 21:42:22 +00:00
Daniel James
e6cb3a77ee Fix a couple of comments.
[SVN r60294]
2010-03-07 13:11:10 +00:00
Daniel James
bbccfbbab4 Remove use of deprecated macro in result_of test.
[SVN r60293]
2010-03-07 13:10:54 +00:00
Daniel James
74a6a693d3 Remove use of deprecated config macro in result_of.
[SVN r60052]
2010-03-01 19:39:52 +00:00
Dave Abrahams
bf713ad47a Revert unintentional reference to "noncopyable_adl_barrier" test that's not checked in.
[SVN r59332]
2010-01-28 14:41:16 +00:00
Dave Abrahams
76b17c497b Support different MS calling conventions, thanks to Nicolas Lelong.
Closes #3833.


[SVN r59247]
2010-01-24 02:08:46 +00:00
Emil Dotchevski
3de5974419 Suppressing warnings. Please report any problems (may have broken something!)
[SVN r58072]
2009-12-01 02:16:50 +00:00
John Maddock
7eb1536590 Suppress/fix some msvc and gcc compiler warnings.
[SVN r57494]
2009-11-08 18:53:59 +00:00
Troy D. Straszheim
9339431e03 rm cmake from trunk. I'm not entirely sure this is necessary to satisfy the inspect script, but I'm not taking any chances, and it is easy to put back
[SVN r56942]
2009-10-17 02:07:38 +00:00
Niels Dekker
f2349baf7d Updated value_init documentation, because the fix of #2548 was not yet included with Boost release 1.40.0.
[SVN r56544]
2009-10-03 09:18:26 +00:00
Niels Dekker
8745ca628a Updated revision date of Boost Swap documentation
[SVN r56108]
2009-09-08 17:07:13 +00:00
Niels Dekker
ba61e9d796 Mentioned swap.hpp header, as requested by Thorsten Ottosen <http://lists.boost.org/Archives/boost/2009/06/153477.php> and David Abrahams <http://lists.boost.org/Archives/boost/2009/09/156064.php>
[SVN r56107]
2009-09-08 16:54:54 +00:00
Troy D. Straszheim
afe74fffbc Copyrights on CMakeLists.txt to keep them from clogging up the inspect
reports.  This is essentially the same commit as r55095 on the release
branch.



[SVN r55159]
2009-07-26 00:49:56 +00:00
Niels Dekker
09a0137016 Reverted value_init revision [54502], intel_9_value_init_conversion-operator.patch from ticket #2548, as it only increased the number of compile errors at the regression page, and Fernando Cacciola also suggested me to leave it broken (without the patch), for this specific (old) compiler version.
[SVN r54832]
2009-07-09 08:06:19 +00:00
Emil Dotchevski
a1d3ec6c53 Documentation update
[SVN r54828]
2009-07-09 03:51:30 +00:00
Emil Dotchevski
5be3004e6c Added commonly used error_info typedefs.
Added boost/exception/all.hpp.
Removed tabs from source files.

[SVN r54825]
2009-07-08 23:44:28 +00:00
Niels Dekker
d387905150 Updated documentation of value_initialized, according to a remark by Daniel James at ticket #2548
[SVN r54503]
2009-06-29 18:04:24 +00:00
Niels Dekker
b514e40733 Worked around Intel 9 specific ambiguity w.r.t. value_initialized conversion operators, by applying intel_9_value_init_conversion-operator.patch, as discussed w/ Daniel James at ticket #2548
[SVN r54502]
2009-06-29 17:53:33 +00:00
Jeremiah Willcock
b02677375f Fixed most tab and min/max issues from trunk inspection report
[SVN r53141]
2009-05-20 19:19:00 +00:00
Steven Watanabe
61a6015b5a Replace aFactoty with aFactory. Fixes #3019
[SVN r53060]
2009-05-17 00:06:34 +00:00
Daniel James
682032a340 Use a local copy of the valid HTML 4.01 icon.
[SVN r53048]
2009-05-16 14:23:59 +00:00
Eric Niebler
67afd7e315 eliminate noisy warning on msvc, fixes #2993
[SVN r52837]
2009-05-07 17:47:08 +00:00
Daniel Frey
75cf20cace primary operand type must be class type, see ticket #2938
[SVN r52463]
2009-04-18 09:06:31 +00:00
Peter Dimov
91385ac627 Another try at the Sun workaround.
[SVN r52010]
2009-03-27 12:50:09 +00:00
Peter Dimov
61e9b93f7c Try the Sun workaround with int instead of size_t.
[SVN r51986]
2009-03-26 13:05:05 +00:00
Peter Dimov
d97b303777 Try to fix array addressof failures on Sun C++.
[SVN r51977]
2009-03-26 00:06:47 +00:00
Peter Dimov
3900e8ece4 Disable new addressof code for all Borland versions. Refs #2878.
[SVN r51891]
2009-03-21 20:20:37 +00:00
Peter Dimov
e27fc4a853 Attempt to fix addressof in trunk to handle classes with conversion operators. Refs #2878.
[SVN r51872]
2009-03-20 17:14:00 +00:00
Peter Dimov
f7aa9a8935 Refs #2128 (fixed in trunk.)
[SVN r51512]
2009-03-01 17:04:14 +00:00
Niels Dekker
0af1959b30 Updated value_initialized documentation and test following changeset [51355].
[SVN r51356]
2009-02-20 20:35:34 +00:00
Niels Dekker
5f0cf4f5de Fixed const issue of value_initialized according to ticket #2548. See also http://lists.boost.org/Archives/boost/2009/02/148489.php
[SVN r51355]
2009-02-20 20:28:54 +00:00
Emil Dotchevski
0282c8a141 added #error in headers incompatible with BOOST_NO_EXCEPTIONS
[SVN r50887]
2009-01-30 00:06:01 +00:00
Emil Dotchevski
6725719bd9 This html was outdated; changed to forward to throw_exception.html documentation from Boost Exception
[SVN r50879]
2009-01-29 19:13:08 +00:00
Niels Dekker
97e11b024e [utility/swap] Distinguished between testing array-of-array-of-class and array-of-array-of-int, as the latter appears to succeed on CodeGear 6.10 while the former does not.
[SVN r49954]
2008-11-27 11:14:52 +00:00
Niels Dekker
118e473a3d [utility/swap] Added comment to various array swapping tests, added member typedef to swap_test_template, to make the test more realistic.
[SVN r49953]
2008-11-27 11:08:05 +00:00
Niels Dekker
d4b6193f94 Replaced swap/test/swap_arrays by more specific tests: array_of_array, array_of_class, and array_of_int.
[SVN r49916]
2008-11-24 17:41:15 +00:00
Niels Dekker
d420c98a53 Added array_of_template test, testing the boost::swap utility on an array of objects of a template class.
[SVN r49862]
2008-11-21 21:28:47 +00:00
Daniel James
d153ab4daa Fix a typo.
[SVN r49811]
2008-11-16 23:10:00 +00:00
Niels Dekker
561f83b991 Updated swap.html because LWG issue 809 is now accepted as a defect. Fixed some HTML formatting.
[SVN r49771]
2008-11-15 15:07:42 +00:00
Michael A. Jackson
57124703f9 Fixing include path to compile with modularized source tree.
[SVN r49685]
2008-11-11 17:22:34 +00:00
Michael A. Jackson
53f6d10652 Updating CMake files to latest trunk. Added dependency information for regression tests and a few new macros for internal use.
[SVN r49627]
2008-11-07 17:02:56 +00:00
Michael A. Jackson
ebe853ff2f Continuing merge of CMake build system files into trunk with the encouragement of Doug Gregor
[SVN r49510]
2008-11-01 13:15:41 +00:00
Niels Dekker
487a5c1ea5 Swap documentation: fixed a misspelling of the name of Steven Watanabe.
[SVN r49416]
2008-10-21 09:55:54 +00:00
Daniel James
c4338b1ce8 Clean up some link errors.
[SVN r48987]
2008-09-28 12:21:39 +00:00
John Maddock
ddd8a58ae0 Fixes #2341.
[SVN r48910]
2008-09-20 15:39:47 +00:00
Matthew Calabrese
28061ba3a8 Removed boost directory binary.hpp.
[SVN r48804]
2008-09-17 01:08:03 +00:00
Matthew Calabrese
5d53e3f837 Changed BOOST_BINARY docs.
[SVN r48641]
2008-09-06 21:51:53 +00:00
Matthew Calabrese
e86ce1cb1f Changed wording for BOOST_BINARY docs.
[SVN r48640]
2008-09-06 21:49:49 +00:00
Matthew Calabrese
f15c96ffb0 Adding binary literal utility.
[SVN r48637]
2008-09-06 21:11:48 +00:00
Douglas Gregor
a487f72329 Fix result_of to work with const-qualified function pointers. Fixes #1310
[SVN r48620]
2008-09-05 19:58:30 +00:00
Emil Dotchevski
9f08ed6de0 minor change in boost/exception.hpp
[SVN r48546]
2008-09-02 21:25:47 +00:00
Emil Dotchevski
2077d0dace simplified further
[SVN r48485]
2008-08-31 02:40:42 +00:00
Emil Dotchevski
7f2348269b Boost Exception now works with BOOST_NO_RTTI and/or BOOST_NO_TYPEID.
[SVN r48429]
2008-08-28 23:49:55 +00:00
Niels Dekker
6b6e1c3252 Added value_initialized::swap documentation + test
[SVN r48425]
2008-08-28 19:00:20 +00:00
Niels Dekker
55f303baec Added value_initialized::swap according to ticket #2243, as agreed with Fernando Cacciola :-)
[SVN r48424]
2008-08-28 18:37:45 +00:00
Niels Dekker
d264005c11 Extended swap_arrays test, checking that boost::swap does correctly exchange the values of its arguments.
[SVN r48247]
2008-08-20 08:29:54 +00:00
Niels Dekker
2cde009bb1 Added extra checks, checking that boost::swap does correctly exchange the values of its arguments, as I mentioned at "Re: [boost] [swap] Renaming boost_swap_impl::swap_impl and/or its namespace?", http://lists.boost.org/Archives/boost/2008/08/141027.php
[SVN r48246]
2008-08-20 08:28:35 +00:00
Niels Dekker
7bfb7c8a61 Added a data member to swap_test_class and made it EqualityComparable, as I mentioned at "Re: [boost] [swap] Renaming boost_swap_impl::swap_impl and/or its namespace?", http://lists.boost.org/Archives/boost/2008/08/141027.php
[SVN r48245]
2008-08-20 08:25:23 +00:00
Niels Dekker
5c42397244 Added explanatory comments, requested by Isaac Dupree, "Re: [boost] [swap] Renaming boost_swap_impl::swap_impl and/or its namespace?", http://lists.boost.org/Archives/boost/2008/08/141007.php
[SVN r48171]
2008-08-16 08:56:19 +00:00
Daniel James
782c132d99 Fix Windows-1252 dash in UTF-8 document.
[SVN r48133]
2008-08-13 22:00:35 +00:00
Daniel Frey
36899afa3f added/switched "euclidean" spelling
[SVN r48025]
2008-08-07 20:47:58 +00:00
Joseph Gauterin
7e3e326faf Updated documentation to remove references to the 'ADL barrier'
[SVN r47973]
2008-08-04 18:25:45 +00:00
Joseph Gauterin
7019e18149 Renamed 'test_adl_barrier.cpp' to 'no_ambiguity_in_boost.cpp' and altered comments to reflect new disambiguation technique.
[SVN r47972]
2008-08-04 18:22:10 +00:00
Joseph Gauterin
49faf23433 Updated copyright info.
[SVN r47971]
2008-08-04 18:16:16 +00:00
Joseph Gauterin
62836f2928 Changed 'using std::swap;' to 'using namesapce std;' in swap_impl function to work around ADL bugs in some compilers.
[SVN r47967]
2008-08-04 11:21:02 +00:00
Niels Dekker
1ecf3ceb74 Added swap tests for std types, as discussed at "Re: [boost] [swap] Workaround for ADL failures of MSVC 7.1 and Borland okay?", http://lists.boost.org/Archives/boost/2008/08/140589.php
[SVN r47943]
2008-08-02 11:41:47 +00:00
Niels Dekker
2aa48414c9 Removed swap_adl_barrier namespace, as discussed at "Re: [boost] [swap] How to fix ADL barrier for XL, Intel, GCC, Sun and Como?", http://lists.boost.org/Archives/boost/2008/07/140511.php
[SVN r47920]
2008-07-31 20:18:04 +00:00
Niels Dekker
d215f2176c Applied "swap.hpp.patch" by Steven Watanabe, "Re: [boost] [swap] How to fix ADL barrier for XL, Intel, GCC, Sun and Como?", http://lists.boost.org/Archives/boost/2008/07/140482.php
[SVN r47877]
2008-07-30 08:04:34 +00:00
Niels Dekker
c286d62223 Fixed comment in swap/test/specialized_in_boost_and_other.cpp
[SVN r47840]
2008-07-27 12:46:45 +00:00
Niels Dekker
3fd0ea6e75 Added specialized_in_boost_and_other to swap/test, as discussed at "[boost] [swap] End-user allowed to add overloads to boost namespace?", http://lists.boost.org/Archives/boost/2008/07/140327.php
[SVN r47839]
2008-07-27 11:35:33 +00:00
Niels Dekker
b050431638 Added a newline to swap/test/lib_header_1.cpp, hoping to fix Sun 5.x compile issue, "Error: There is extra text on this line"
[SVN r47829]
2008-07-26 17:47:59 +00:00
Niels Dekker
b311fcefb2 Added test_adl_barrier to swap/test, as discussed with Joseph Gauterin.
[SVN r47808]
2008-07-25 18:48:09 +00:00
Niels Dekker
899c92420c Fixed silly little typo of mine, in test/swap_arrays.cpp
[SVN r47629]
2008-07-20 12:18:25 +00:00
Niels Dekker
64a0e0cb20 Added swap_test_class swap functions to test/swap_arrays.cpp. My fault, they should have been there already!
[SVN r47628]
2008-07-20 12:13:33 +00:00
Niels Dekker
ece6992540 Fixed silly little bug of mine in swap/test/swap_arrays.cpp
[SVN r47626]
2008-07-20 11:05:49 +00:00
Joseph Gauterin
6098304ea8 Corrected duplicated file contents
[SVN r47607]
2008-07-19 19:40:12 +00:00
Vladimir Prus
28fff2d821 Remove duplicate content.
[SVN r47360]
2008-07-12 17:56:01 +00:00
Ronald Garcia
0ce3885d59 Added an anonymous unwrapping test.
[SVN r47297]
2008-07-10 23:01:26 +00:00
Ronald Garcia
1823481d96 Added tests for unwrap_ref.
[SVN r47296]
2008-07-10 19:29:02 +00:00
Ronald Garcia
cce5d77d2b Added unwrap_ref.
[SVN r47295]
2008-07-10 19:28:49 +00:00
Joseph Gauterin
3c5c2bc107 Moved utility\swap to the trunk, as discussed in trac issue #2056.
[SVN r47093]
2008-07-05 11:16:38 +00:00
Beman Dawes
177ee78bbb With his kind permission, change Jaakko "Järvi" to "Jarvi"
[SVN r46808]
2008-06-28 13:45:21 +00:00
Daniel James
f1ec0c4d04 Fix a character encoding error.
[SVN r46740]
2008-06-26 19:20:56 +00:00
Emil Dotchevski
4a564744fe documentation update, added function exception::diagnostic_information, added std::exception to_string overload, removed tabs from source files
[SVN r46697]
2008-06-25 23:27:56 +00:00
Niels Dekker
67f3ca090a Fixed value_init test + doc, according to change of boost::initialized_value, revision [45685]
[SVN r45686]
2008-05-23 16:48:10 +00:00
Niels Dekker
8efae71f4a Changed boost::initialized_value from a class to an instance, to make its use more convenient, as discussed with Fernando.
[SVN r45685]
2008-05-23 16:46:43 +00:00
Douglas Gregor
ad0bcf4a00 result_of implementation that makes use of C++0x decltype, from Daniel Walker. Fixes #862.
[SVN r45256]
2008-05-09 22:08:46 +00:00
Daniel James
f1c86c35c4 Merge in documentation fixes. Apart from the change to optional's documenation
Jamfile, which I included by mistake.

Fixes #1659, #1661, #1684, #1685, 1687, #1690, #1801

I wrote about this at:

http://lists.boost.org/Archives/boost/2008/04/136405.php

Merged revisions 44585-44806 via svnmerge from 
https://svn.boost.org/svn/boost/branches/doc

........
  r44585 | danieljames | 2008-04-19 16:25:27 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Fix broken link to vacpp in bjam docs. Refs #1512
........
  r44586 | danieljames | 2008-04-19 16:27:36 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Fix broken link to bcpp in bjam docs. Refs #1513
........
  r44587 | danieljames | 2008-04-19 16:33:58 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  DateTime documentation - Fix a link to the serialization library. Refs #1659
........
  r44588 | danieljames | 2008-04-19 16:35:36 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Fix some links in interprocess & intrusive. Refs #1661
........
  r44589 | danieljames | 2008-04-19 16:37:39 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Fix some links in the python docs. Refs #1684.
........
  r44590 | danieljames | 2008-04-19 16:38:29 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Work around a quickbook bug which is affecting the python docs. Refs #1684.
........
  r44591 | danieljames | 2008-04-19 16:39:34 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Fix a broken link in the numeric conversion docs. Refs #1685
........
  r44592 | danieljames | 2008-04-19 16:40:45 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Fix some links in the optional docs. Refs #1687
........
  r44593 | danieljames | 2008-04-19 16:42:09 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Fix link to the hash documentation from bimap. Refs #1690
........
  r44599 | danieljames | 2008-04-19 18:07:33 +0100 (Sat, 19 Apr 2008) | 2 lines
  
  Fix a typo in the format library. Refs #1801
........
  r44600 | danieljames | 2008-04-19 19:20:59 +0100 (Sat, 19 Apr 2008) | 1 line
  
  Initialise svnmerge.
........
  r44641 | danieljames | 2008-04-20 18:59:47 +0100 (Sun, 20 Apr 2008) | 2 lines
  
  Fix the lincense url in shared container iterator documentation.
........
  r44642 | danieljames | 2008-04-20 19:00:00 +0100 (Sun, 20 Apr 2008) | 2 lines
  
  Fix image link in the mpi documentation.
........
  r44643 | danieljames | 2008-04-20 19:00:11 +0100 (Sun, 20 Apr 2008) | 2 lines
  
  Fix a typo in the spirit docs.
........
  r44644 | danieljames | 2008-04-20 19:00:23 +0100 (Sun, 20 Apr 2008) | 2 lines
  
  Escape the slash so that quickbook doesn't think it the start of an italic section, and mess up the link. Refs #1844
........
  r44647 | danieljames | 2008-04-20 19:39:47 +0100 (Sun, 20 Apr 2008) | 2 lines
  
  Fix another typo in spirit docs.
........


[SVN r44807]
2008-04-27 07:39:49 +00:00
Peter Dimov
a5b85eda07 Fix #1846.
[SVN r44705]
2008-04-21 21:42:29 +00:00
Emil Dotchevski
bafe37fdab Boost Exception header compilation tests added.
[SVN r44442]
2008-04-15 21:13:24 +00:00
Daniel Frey
be50b95508 Added test and fix for "convertible to bool" requirement
[SVN r44151]
2008-04-10 14:38:14 +00:00
Marshall Clow
96d573d6ca Replaced all occurrences of non-ASCII copyright symbol with '(c)' for people using non-ASCII code pages
[SVN r43992]
2008-04-02 01:42:32 +00:00
John Maddock
2412b864d6 Fix some inspection report issues.
[SVN r43633]
2008-03-15 18:41:51 +00:00
Emil Dotchevski
94865eabe6 boost exception
[SVN r43485]
2008-03-04 01:41:17 +00:00
Niels Dekker
50268d1b29 Tested the assignment of value_initialized<T>, for T being a C-style array. Related to the fix of changeset [43308]
[SVN r43309]
2008-02-18 22:13:21 +00:00
Niels Dekker
ad9108c1dc Fixed the assignment of value_initialized<T> for T being a C-style array. (The previous version would trigger a compile error in this case.)
[SVN r43308]
2008-02-18 22:11:19 +00:00
Daniel James
691e4b6c34 Link to people pages on the website, as they've been removed from the download.
[SVN r43209]
2008-02-10 14:56:22 +00:00
Niels Dekker
28596e678d value_init: Removed aligned_storage::address() calls, to improve TR1 compatibility, as confirmed by John Maddock. Added internal helper function, wrapper_address(), as discussed with Fernando.
[SVN r43025]
2008-01-30 22:42:23 +00:00
Niels Dekker
1beca24dd8 Removed local named variable from value_initialized::operator=, as Fernando Cacciola suggested me to avoid unnecessary named variables.
[SVN r42869]
2008-01-19 20:52:04 +00:00
Niels Dekker
721764937f value_init_test now works around Borland 5.82 bug ("Error E2015: Ambiguity..." when using initialized_value), that is fixed with a newer compiler version
[SVN r42868]
2008-01-19 20:21:18 +00:00
Niels Dekker
a511007d0f Added test and documentation for convenience class initialized_value, that was added with changeset [42815]
[SVN r42816]
2008-01-16 09:37:25 +00:00
Niels Dekker
8ce58b1675 Added convenience class initialized_value, as announced at http://article.gmane.org/gmane.comp.lib.boost.devel/169833
[SVN r42815]
2008-01-16 09:35:12 +00:00
Niels Dekker
9ed68b8321 value_init doc + test: Added revision date.
[SVN r42798]
2008-01-15 19:53:28 +00:00
Niels Dekker
79bbf71d0d Minor "beautifications" of value_init documentation, inc. placing references in order of appearance
[SVN r42779]
2008-01-14 21:46:20 +00:00
Niels Dekker
ac93de7c1b Documented value_init workaround to compiler issues, added new introduction, updated to 2003 edition of C++ Standard -- reviewed by Fernando Cacciola
[SVN r42771]
2008-01-14 18:17:30 +00:00
Niels Dekker
d731b8e1c5 Added value_init tests, testing copy construction and assignment.
[SVN r42278]
2007-12-24 22:00:37 +00:00
Niels Dekker
ac1567b3fc value_init now uses aligned_storage::address(), instead of "&x", as recommended by Fernando Cacciola (by mail)
[SVN r42277]
2007-12-24 20:42:16 +00:00
Douglas Gregor
c1fd670480 Reduce header dependencies, from Shunsuke Sogame. Fixes #1535
[SVN r42234]
2007-12-21 21:18:17 +00:00
Niels Dekker
01274cf6ac value_init.hpp now no longer distinguished between workaround and non-workaround, because many compilers don't do value-initialization well. Fixed copy construction and assignment -- discussed with Fernando Cacciola
[SVN r41942]
2007-12-09 22:49:58 +00:00
Niels Dekker
8080673977 Added value_init tests if a copy function of T is called when value_initialized<T> is copied -- a case I hadn't thought of before...
[SVN r41919]
2007-12-09 11:53:08 +00:00
Niels Dekker
a470b591fb Added value_init test for an value_initialized<T> object allocated on the heap.
[SVN r41667]
2007-12-03 21:41:59 +00:00
Niels Dekker
e1a63495b6 Added missing #include to value_init_test.cpp. (My mistake!)
[SVN r41648]
2007-12-03 18:20:19 +00:00
Niels Dekker
7300ac83f1 Added value_init test for C style array of bytes
[SVN r41647]
2007-12-03 18:14:37 +00:00
Niels Dekker
882d38c2c7 Added value_init tests, based upon GCC bug report by Jonathan Wakely. Added URL to Borland bug report.
[SVN r41529]
2007-12-01 12:14:37 +00:00
Niels Dekker
33041ad664 Added tests for two more struct types to value_init_test -- discussed with Fernando Cacciola
[SVN r41436]
2007-11-28 17:19:37 +00:00
Niels Dekker
6a2aa822f8 Added value_init test for struct as used in MSVC bug report regarding value-initialization.
[SVN r41423]
2007-11-27 21:34:08 +00:00
Niels Dekker
09ab16bfc1 Checked the result of value_init test function, hoping to pinpoint exactly for what particular type T value_initialized<T> might fail, on some platforms
[SVN r41326]
2007-11-24 11:51:03 +00:00
Niels Dekker
ec46e40809 Code refactoring: removed private base classes of value_initialized, as suggested by Fernando Cacciola.
[SVN r41216]
2007-11-18 22:11:57 +00:00
Beman Dawes
b3a971e7e9 Copyright and/or License cleanup
[SVN r40890]
2007-11-07 16:08:09 +00:00
John Maddock
7ddb559887 Fix path to test case.
[SVN r40736]
2007-11-04 12:01:16 +00:00
Peter Dimov
ea8c99b1d5 Added a sentence with a brief explanation of the intended uses of BOOST_VERIFY.
[SVN r40731]
2007-11-03 22:47:17 +00:00
Peter Dimov
56b0846099 BOOST_VERIFY added.
[SVN r40728]
2007-11-03 20:55:22 +00:00
Niels Dekker
42e0001370 Added value_initialized<T> test, having T as aggregate POD struct. In the past, this would have triggered MSVC warning C4345; this warning is now disabled within value_init.hpp, changeset [40088]
[SVN r40089]
2007-10-16 17:06:39 +00:00
Niels Dekker
cd8f85afee Disabled MSVC warning C4345, in response to Gennadiy Rozental, Boost Developer mailing list, "[utility] value_init warning", October 14, 2007. Push'n'pop reminder from Paul A Bristow taken into account.
[SVN r40088]
2007-10-16 17:00:28 +00:00
Markus Schöpflin
bddd52c4b9 Fixed bug preventing compilation on Tru64/CXX.
[SVN r39918]
2007-10-11 07:36:41 +00:00
Niels Dekker
8f03aeac4e Added unit test to make sure that Visual C++ 7.1 ICE reported by Ralf W. Grosse-Kunstleve (Boost Developers mailing list, subject "utility/value_init.hpp: VC 7.1 ICE & workaround") will not occur anymore.
[SVN r39309]
2007-09-16 09:48:28 +00:00
Niels Dekker
3bb2568fad Visual C++ 7.1 ICE workaround by Ralf W. Grosse-Kunstleve added to ~const_T_base() as well. See also Boost Developers mailing list, subject "utility/value_init.hpp: VC 7.1 ICE & workaround"
[SVN r39308]
2007-09-16 09:33:34 +00:00
Ralf W. Grosse-Kunstleve
01e91a3799 work around Visual C++ 7.1 internal compiler error
[SVN r39302]
2007-09-15 23:11:50 +00:00
Niels Dekker
55f3c351a3 Added MSVC workaround to value_initialized, as described by ticket #1217, proposed at the Boost Developers mailing list, and discussed with Fernando Cacciola.
[SVN r39157]
2007-09-07 17:17:09 +00:00
Vladimir Prus
3f72b10182 Remove V1 Jamfiles
[SVN r38516]
2007-08-08 19:02:26 +00:00
Eric Niebler
71cb8cb574 broken msvc name look-up getting confused about which detail namespace
[SVN r38511]
2007-08-08 18:05:24 +00:00
Tobias Schwinger
c950825ef4 - overloads apply for array construction
- adds support for zero arguments
- lets apply return the result of the new-expression
- revises the preprocessing code


[SVN r38101]
2007-06-26 23:07:25 +00:00
Douglas Gregor
66ca84a45d Update result_of information
[SVN r38024]
2007-06-18 12:48:37 +00:00
Daniel Frey
06404f7d39 Improved empty_base
[SVN r37754]
2007-05-23 22:48:42 +00:00
Douglas Gregor
2d860e2574 Fix result_of's handling of F(void).
[SVN r37140]
2007-03-05 15:25:16 +00:00
Eric Niebler
66514f61ff fix result_of ambiguity error for nullary functions
[SVN r36773]
2007-01-24 06:44:20 +00:00
Eric Niebler
63cde4d3fd slightly modified implementation works around msvc 7.1/8.0 compiler bugs
[SVN r36668]
2007-01-08 20:38:51 +00:00
Daniel James
1950f292df Merge fixed links from RC_1_34_0.
[SVN r36660]
2007-01-07 23:50:56 +00:00
Andreas Huber
92a0602190 Fixed license & copyright issues and converted to HTML 4.01
[SVN r36280]
2006-12-05 21:11:21 +00:00
Peter Dimov
c9a3ab1d04 Linked to current_function.html
[SVN r36268]
2006-12-04 20:31:38 +00:00
Vladimir Prus
0782034333 Allow building of shared versions of some Boost.Test libraries.
Adjust tests to use always use static linking to Boost.Test, since
linking to the shared version requires test changes.

Patch from Juergen Hunold.


[SVN r35989]
2006-11-10 19:09:56 +00:00
Peter Dimov
0808883f3c License/copyright edits
[SVN r35958]
2006-11-09 20:34:33 +00:00
Beman Dawes
2f69501e55 Add copyright, license
[SVN r35905]
2006-11-07 19:11:57 +00:00
John Maddock
5b83f641a8 Removed unneeded semicolon.
[SVN r35636]
2006-10-16 18:01:40 +00:00
Dave Abrahams
c730ab4ffb Parameter library Workarounds for Borland and MSVC
Parameter library explicit markup for expected failures

value_init.hpp:
  Borland workarounds
  Use angle-includes consistently


[SVN r35084]
2006-09-13 03:00:18 +00:00
Fernando Cacciola
e55610a0d0 Some additional functions added to optional (being new there won't be regressions)
[SVN r34411]
2006-06-26 18:01:38 +00:00
Hartmut Kaiser
bf968794c9 Fixed an ambiguity.
[SVN r34403]
2006-06-26 01:58:38 +00:00
Peter Dimov
ce6e9c6698 Digital Mars support (Pavel Vozenilek)
[SVN r34373]
2006-06-22 12:47:19 +00:00
Dave Abrahams
7ac180ed54 Use forwarding to get SFINAE effect in some common use cases.
Rename detail::result_of to detail::result_of_impl to avoid surprises
when result_of is used from within boost::detail.


[SVN r33981]
2006-05-16 22:55:27 +00:00
26 changed files with 1544 additions and 155 deletions

View File

@@ -17,36 +17,89 @@
<td colspan="2" height="64">&nbsp;</td> <td colspan="2" height="64">&nbsp;</td>
</tr> </tr>
</table> </table>
<p>
<a href="#BOOST_ASSERT">BOOST_ASSERT</a><br>
<a href="#BOOST_ASSERT_MSG">BOOST_ASSERT_MSG</a><br>
<a href="#BOOST_VERIFY">BOOST_VERIFY</a></p>
<h2><a name="BOOST_ASSERT">BOOST_ASSERT</a></h2>
<p> <p>
The header <STRONG>&lt;boost/assert.hpp&gt;</STRONG> defines the macro <b>BOOST_ASSERT</b>, The header <STRONG>&lt;boost/assert.hpp&gt;</STRONG> defines the macro <b>BOOST_ASSERT</b>,
which is similar to the standard <STRONG>assert</STRONG> macro defined in <STRONG>&lt;cassert&gt;</STRONG>. which is similar to the standard <STRONG>assert</STRONG> macro defined in <STRONG>&lt;cassert&gt;</STRONG>.
The macro is intended to be used in Boost libraries. The macro is intended to be used in both Boost libraries and user
code.
</p> </p>
<P>By default, <tt>BOOST_ASSERT(expr)</tt> is equivalent to <tt>assert(expr)</tt>.</P> <P>By default, <tt>BOOST_ASSERT(expr)</tt> is equivalent to <tt>assert(expr)</tt>.</P>
<P>When the macro <STRONG>BOOST_DISABLE_ASSERTS</STRONG> is defined when <STRONG>&lt;boost/assert.hpp&gt;</STRONG> <P>If the macro <STRONG>BOOST_DISABLE_ASSERTS</STRONG> is defined when <STRONG>&lt;boost/assert.hpp&gt;</STRONG>
is included, <tt>BOOST_ASSERT(expr)</tt> is defined as <tt>((void)0)</tt>. This is included, <tt>BOOST_ASSERT(expr)</tt> is defined as <tt>((void)0)</tt>. This
allows users to selectively disable <STRONG>BOOST_ASSERT</STRONG> without allows users to selectively disable <STRONG>BOOST_ASSERT</STRONG> without
affecting the definition of the standard <STRONG>assert</STRONG>.</P> affecting the definition of the standard <STRONG>assert</STRONG>.</P>
<P>When the macro <STRONG>BOOST_ENABLE_ASSERT_HANDLER</STRONG> is defined when <STRONG>&lt;boost/assert.hpp&gt;</STRONG> <P>If the macro <STRONG>BOOST_ENABLE_ASSERT_HANDLER</STRONG> is defined when <STRONG>&lt;boost/assert.hpp&gt;</STRONG>
is included, <tt>BOOST_ASSERT(expr)</tt> evaluates <b>expr</b> and, if the is included, <tt>BOOST_ASSERT(expr)</tt> evaluates <b>expr</b> and, if the
result is false, evaluates the expression</P> result is false, evaluates the expression</P>
<blockquote>
<P><tt>::boost::assertion_failed(#expr, <a href="current_function.html">BOOST_CURRENT_FUNCTION</a>, <P><tt>::boost::assertion_failed(#expr, <a href="current_function.html">BOOST_CURRENT_FUNCTION</a>,
__FILE__, __LINE__)</tt></P> __FILE__, __LINE__)</tt></P>
</blockquote>
<P><STRONG>assertion_failed</STRONG> is declared in <STRONG>&lt;boost/assert.hpp&gt;</STRONG> <P><STRONG>assertion_failed</STRONG> is declared in <STRONG>&lt;boost/assert.hpp&gt;</STRONG>
as</P> as</P>
<pre> <blockquote>
namespace boost <pre>namespace boost
{ {
void assertion_failed(char const * expr, char const * function, char const * file, long line);
void assertion_failed(char const * expr, char const * function, char const * file, long line);
} }
</pre> </pre>
</blockquote>
<p>but it is never defined. The user is expected to supply an appropriate <p>but it is never defined. The user is expected to supply an appropriate
definition.</p> definition.</p>
<P>As is the case with <STRONG>&lt;cassert&gt;</STRONG>, <STRONG>&lt;boost/assert.hpp&gt;</STRONG> <P>As is the case with <STRONG>&lt;cassert&gt;</STRONG>, <STRONG>&lt;boost/assert.hpp&gt;</STRONG>
can be included multiple times in a single translation unit. <STRONG>BOOST_ASSERT</STRONG> can be included multiple times in a single translation unit. <STRONG>BOOST_ASSERT</STRONG>
will be redefined each time as specified above.</P> will be redefined each time as specified above.</P>
<h2><a name="BOOST_ASSERT_MSG">BOOST_ASSERT_MSG</a></h2>
<p>
The header <STRONG>&lt;boost/assert.hpp&gt;</STRONG> defines the macro <b>BOOST_ASSERT_MSG</b>,
which is similar to the standard <STRONG>assert</STRONG> macro defined in <STRONG>&lt;cassert&gt;</STRONG>,
but with an additional macro parameter supplying an error message. The macro is intended to be used in both Boost libraries
and user code.
</p>
<P> <tt>BOOST_ASSERT_MSG(expr, msg)</tt> is equivalent to <code>
((void)0)</code> if <b>BOOST_DISABLE_ASSERTS</b> or <b>NDEBUG</b> are
defined or <code>expr</code> evaluates to <code>true</code>. If those
macros and <STRONG>BOOST_ENABLE_ASSERT_HANDLER</STRONG> are not
defined, and <code>expr</code> evaluates to <code>false</code>, an error
message that includes <tt>#expr</tt>, <tt>msg</tt>, <tt> <a href="current_function.html">BOOST_CURRENT_FUNCTION</a></tt>, <tt>
__FILE__</tt>, and <tt>__LINE__</tt> is sent to output stream <b>
BOOST_ASSERT_MSG_OSTREAM</b>
and <code>std::abort()</code> is called.</P>
<P> <b>BOOST_ASSERT_MSG_OSTREAM</b> defines the output stream. It defaults to <code>std::cerr</code>.
Integrated development environments (IDE's) like Microsoft Visual Studio
may produce easier to understand output if messages go to a different
stream, such as <code>std::cout</code>. Users may define <b>BOOST_ASSERT_MSG_OSTREAM</b> before including <STRONG>&lt;boost/assert.hpp&gt;</STRONG>
to specify a different output stream.&nbsp; </P>
<P>If the macro <STRONG>BOOST_ENABLE_ASSERT_HANDLER</STRONG> is defined when <STRONG>&lt;boost/assert.hpp&gt;</STRONG>
is included, instead of sending a error message to an output
stream, this expression is evaluated</P>
<blockquote>
<P><tt>::boost::assertion_failed_msg(#expr, msg, <a href="current_function.html">BOOST_CURRENT_FUNCTION</a>,
__FILE__, __LINE__)</tt></P>
</blockquote>
<P><STRONG>assertion_failed_msg</STRONG> is declared in <STRONG>&lt;boost/assert.hpp&gt;</STRONG>
as</P>
<blockquote>
<pre>namespace boost
{
void assertion_failed_msg(char const * expr, char const * msg, char const * function, char const * file, long line);
}
</pre>
</blockquote>
<p>but it is never defined. The user is expected to supply an appropriate
definition.</p>
<P>As is the case with <STRONG>&lt;cassert&gt;</STRONG>, <STRONG>&lt;boost/assert.hpp&gt;</STRONG>
can be included multiple times in a single translation unit. <STRONG>BOOST_ASSERT_MSG</STRONG>
will be redefined each time as specified above.</P>
<h2><a name="BOOST_VERIFY">BOOST_VERIFY</a></h2>
<p><STRONG>&lt;boost/assert.hpp&gt;</STRONG> also defines the macro <STRONG>BOOST_VERIFY</STRONG>. <p><STRONG>&lt;boost/assert.hpp&gt;</STRONG> also defines the macro <STRONG>BOOST_VERIFY</STRONG>.
It has exactly the same behavior as <STRONG>BOOST_ASSERT</STRONG>, except that It has exactly the same behavior as <STRONG>BOOST_ASSERT</STRONG>, except that
the expression that is passed to <STRONG>BOOST_VERIFY</STRONG> is always the expression that is passed to <STRONG>BOOST_VERIFY</STRONG> is always
@@ -54,8 +107,9 @@ void assertion_failed(char const * expr, char const * function, char const * fil
effects; it can also help suppress warnings about unused variables when the effects; it can also help suppress warnings about unused variables when the
only use of the variable is inside an assertion.</p> only use of the variable is inside an assertion.</p>
<p><br> <p><br>
<small>Copyright <20> 2002, 2007 by Peter Dimov. Distributed under the Boost Software <small>Copyright <20> 2002, 2007 by Peter Dimov.&nbsp; Copyright <20> 2011
by Beman Dawes. Distributed under the Boost Software
License, Version 1.0. See accompanying file <A href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</A> License, Version 1.0. See accompanying file <A href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</A>
or copy at <A href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>.</small></p> or copy at <A href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>.</small></p>
</body> </body>
</html> </html>

View File

@@ -2,6 +2,7 @@
// assert_test.cpp - a test for boost/assert.hpp // assert_test.cpp - a test for boost/assert.hpp
// //
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. // Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
// Copyright (2) Beman Dawes 2011
// //
// Distributed under the Boost Software License, Version 1.0. (See // Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at // accompanying file LICENSE_1_0.txt or copy at
@@ -20,6 +21,11 @@ void test_default()
BOOST_ASSERT(x); BOOST_ASSERT(x);
BOOST_ASSERT(x == 1); BOOST_ASSERT(x == 1);
BOOST_ASSERT(&x); BOOST_ASSERT(&x);
BOOST_ASSERT_MSG(1, "msg");
BOOST_ASSERT_MSG(x, "msg");
BOOST_ASSERT_MSG(x == 1, "msg");
BOOST_ASSERT_MSG(&x, "msg");
} }
#define BOOST_DISABLE_ASSERTS #define BOOST_DISABLE_ASSERTS
@@ -34,13 +40,23 @@ void test_disabled()
BOOST_ASSERT(x == 1); BOOST_ASSERT(x == 1);
BOOST_ASSERT(&x); BOOST_ASSERT(&x);
BOOST_ASSERT_MSG(1, "msg");
BOOST_ASSERT_MSG(x, "msg");
BOOST_ASSERT_MSG(x == 1, "msg");
BOOST_ASSERT_MSG(&x, "msg");
BOOST_ASSERT(0); BOOST_ASSERT(0);
BOOST_ASSERT(!x); BOOST_ASSERT(!x);
BOOST_ASSERT(x == 0); BOOST_ASSERT(x == 0);
BOOST_ASSERT_MSG(0, "msg");
BOOST_ASSERT_MSG(!x, "msg");
BOOST_ASSERT_MSG(x == 0, "msg");
void * p = 0; void * p = 0;
BOOST_ASSERT(p); BOOST_ASSERT(p);
BOOST_ASSERT_MSG(p, "msg");
// supress warnings // supress warnings
p = &x; p = &x;
@@ -55,6 +71,7 @@ void test_disabled()
#include <cstdio> #include <cstdio>
int handler_invoked = 0; int handler_invoked = 0;
int msg_handler_invoked = 0;
void boost::assertion_failed(char const * expr, char const * function, char const * file, long line) void boost::assertion_failed(char const * expr, char const * function, char const * file, long line)
{ {
@@ -66,11 +83,24 @@ void boost::assertion_failed(char const * expr, char const * function, char cons
++handler_invoked; ++handler_invoked;
} }
void boost::assertion_failed_msg(char const * expr, char const * msg, char const * function,
char const * file, long line)
{
#if !defined(BOOST_NO_STDC_NAMESPACE)
using std::printf;
#endif
printf("Expression: %s Message: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n",
expr, msg, function, file, line);
++msg_handler_invoked;
}
struct X struct X
{ {
static void f() static void f()
{ {
BOOST_ASSERT(0); BOOST_ASSERT(0);
BOOST_ASSERT_MSG(0, "msg f()");
} }
}; };
@@ -83,21 +113,35 @@ void test_handler()
BOOST_ASSERT(x == 1); BOOST_ASSERT(x == 1);
BOOST_ASSERT(&x); BOOST_ASSERT(&x);
BOOST_ASSERT_MSG(1, "msg2");
BOOST_ASSERT_MSG(x, "msg3");
BOOST_ASSERT_MSG(x == 1, "msg4");
BOOST_ASSERT_MSG(&x, "msg5");
BOOST_ASSERT(0); BOOST_ASSERT(0);
BOOST_ASSERT(!x); BOOST_ASSERT(!x);
BOOST_ASSERT(x == 0); BOOST_ASSERT(x == 0);
BOOST_ASSERT_MSG(0,"msg 0");
BOOST_ASSERT_MSG(!x, "msg !x");
BOOST_ASSERT_MSG(x == 0, "msg x == 0");
void * p = 0; void * p = 0;
BOOST_ASSERT(p); BOOST_ASSERT(p);
BOOST_ASSERT_MSG(p, "msg p");
X::f(); X::f();
BOOST_ASSERT(handler_invoked == 5); BOOST_ASSERT(handler_invoked == 5);
BOOST_TEST(handler_invoked == 5); BOOST_TEST(handler_invoked == 5);
BOOST_ASSERT_MSG(msg_handler_invoked == 5, "msg_handler_invoked count is wrong");
BOOST_TEST(msg_handler_invoked == 5);
} }
#undef BOOST_ENABLE_ASSERT_HANDLER #undef BOOST_ENABLE_ASSERT_HANDLER
#undef BOOST_ENABLE_ASSERT_MSG_HANDLER
int main() int main()
{ {

68
doc/Jamfile.v2 Normal file
View File

@@ -0,0 +1,68 @@
# Copyright John Maddock 2005. Use, modification, and distribution are
# subject to the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
project : requirements
# Path for links to Boost:
<xsl:param>boost.root=../../../..
# Some general style settings:
<xsl:param>table.footnote.number.format=1
<xsl:param>footnote.number.format=1
# HTML options first:
# Use graphics not text for navigation:
<xsl:param>navig.graphics=1
# PDF Options:
# TOC Generation: this is needed for FOP-0.9 and later:
<xsl:param>fop1.extensions=0
<xsl:param>xep.extensions=1
# TOC generation: this is needed for FOP 0.2, but must not be set to zero for FOP-0.9!
<xsl:param>fop.extensions=0
# No indent on body text:
<xsl:param>body.start.indent=0pt
# Margin size:
<xsl:param>page.margin.inner=0.5in
# Margin size:
<xsl:param>page.margin.outer=0.5in
# Paper type = A4
<xsl:param>paper.type=A4
# Yes, we want graphics for admonishments:
<xsl:param>admon.graphics=1
# Set this one for PDF generation *only*:
# default pnd graphics are awful in PDF form,
# better use SVG's instead:
<format>pdf:<xsl:param>admon.graphics.extension=".svg"
<format>pdf:<xsl:param>admon.graphics.path=$(boost-images)/
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/libs/utility/doc/html
;
using quickbook ;
path-constant boost-images : ../../../doc/src/images ;
xml declval : declval.qbk ;
boostbook standalone
:
declval
:
# File name of HTML output:
<xsl:param>root.filename=declval
# How far down we chunk nested sections, basically all of them:
<xsl:param>chunk.section.depth=0
# Don't put the first section on the same page as the TOC:
<xsl:param>chunk.first.sections=0
# How far down sections get TOC's
<xsl:param>toc.section.depth=1
# Max depth in each TOC:
<xsl:param>toc.max.depth=1
# How far down we go with TOC's
<xsl:param>generate.section.toc.level=1
;

104
doc/declval.qbk Normal file
View File

@@ -0,0 +1,104 @@
[/
/ Copyright (c) 2008 Howard Hinnant
/ Copyright (c) 2008 Beman Dawes
/ Copyright (c) 2009-20010 Vicente J. Botet Escriba
/
/ Distributed under the Boost Software License, Version 1.0. (See accompanying
/ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
/]
[article Declval
[quickbook 1.5]
[authors [Hinnant, Howard]]
[authors [Dawes, Beman]]
[authors [Botet Escriba, Vicente J.]]
[copyright 2008 Howard Hinnant]
[copyright 2008 Beman Dawes]
[copyright 2009-2010 Vicente J. Botet Escriba]
[license
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
[@http://www.boost.org/LICENSE_1_0.txt])
]
]
[/===============]
[section Overview]
[/===============]
The motivation for `declval` was introduced in [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2958.html#Value N2958:
Moving Swap Forward]. Here follows a rewording of this chapter.
With the provision of decltype, late-specified return types, and default template-arguments for function templates a
new generation of SFINAE patterns will emerge to at least partially compensate the lack of concepts on the C++0x timescale.
Using this technique, it is sometimes necessary to obtain an object of a known type in a non-using context, e.g. given the declaration
template<class T>
T&& declval(); // not used
as part of the function template declaration
template<class To, class From>
decltype(static_cast<To>(declval<From>())) convert(From&&);
or as part of a class template definition
template<class> class result_of;
template<class Fn, class... ArgTypes>
struct result_of<Fn(ArgTypes...)>
{
typedef decltype(declval<Fn>()(declval<ArgTypes>()...)) type;
};
The role of the function template declval() is a transformation of a type T into a value without using or evaluating this function.
The name is supposed to direct the reader's attention to the fact that the expression `declval<T>()` is an lvalue if and only if
T is an lvalue-reference, otherwise an rvalue. To extend the domain of this function we can do a bit better by changing its declaration to
template<class T>
typename std::add_rvalue_reference<T>::type declval(); // not used
which ensures that we can also use cv void as template parameter. The careful reader might have noticed that `declval()`
already exists under the name create() as part of the definition of the semantics of the type trait is_convertible in the C==0x standard.
The provision of a new library component that allows the production of values in unevaluated expressions is considered as
important to realize constrained templates in C++0x where concepts are not available.
This extremely light-weight function is expected to be part of the daily tool-box of the C++0x programmer.
[endsect]
[/=================]
[section:reference Reference ]
[/=================]
`#include <boost/utility/declval.hpp>`
namespace boost {
template <typename T>
typename add_rvalue_reference<T>::type declval(); //noexcept; // as unevaluated operand
} // namespace boost
The library provides the function template declval to simplify the definition of expressions which occur as unevaluated operands.
template <typename T>
typename add_rvalue_reference<T>::type declval();
[*Remarks:] If this function is used, the program is ill-formed.
[*Remarks:] The template parameter T of declval may be an incomplete type.
[*Example:]
template <class To, class From>
decltype(static_cast<To>(declval<From>())) convert(From&&);
Declares a function template convert which only participats in overloading if the type From can be explicitly converted to type To.
[endsect]

163
doc/html/declval.html Normal file
View File

@@ -0,0 +1,163 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Declval</title>
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
<link rel="home" href="declval.html" title="Declval">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
<td align="center"><a href="../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav"></div>
<div class="article" lang="en">
<div class="titlepage">
<div>
<div><h2 class="title">
<a name="declval"></a>Declval</h2></div>
<div><div class="authorgroup">
<div class="author"><h3 class="author">
<span class="firstname">Howard</span> <span class="surname">Hinnant</span>
</h3></div>
<div class="author"><h3 class="author">
<span class="firstname">Beman</span> <span class="surname">Dawes</span>
</h3></div>
<div class="author"><h3 class="author">
<span class="firstname">Vicente J.</span> <span class="surname">Botet Escriba</span>
</h3></div>
</div></div>
<div><p class="copyright">Copyright &#169; 2008 Howard Hinnant</p></div>
<div><p class="copyright">Copyright &#169; 2008 Beman Dawes</p></div>
<div><p class="copyright">Copyright &#169; 2009 -2010 Vicente J. Botet Escriba</p></div>
<div><div class="legalnotice">
<a name="id879409"></a><p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></div>
</div>
<hr>
</div>
<div class="toc">
<p><b>Table of Contents</b></p>
<dl>
<dt><span class="section"><a href="declval.html#declval.overview">Overview</a></span></dt>
<dt><span class="section"><a href="declval.html#declval.reference"> Reference </a></span></dt>
</dl>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="declval.overview"></a><a class="link" href="declval.html#declval.overview" title="Overview">Overview</a>
</h2></div></div></div>
<p>
The motivation for <code class="computeroutput"><span class="identifier">declval</span></code>
was introduced in <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2958.html#Value" target="_top">N2958:
Moving Swap Forward</a>. Here follows a rewording of this chapter.
</p>
<p>
With the provision of decltype, late-specified return types, and default template-arguments
for function templates a new generation of SFINAE patterns will emerge to at
least partially compensate the lack of concepts on the C++0x timescale. Using
this technique, it is sometimes necessary to obtain an object of a known type
in a non-using context, e.g. given the declaration
</p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="identifier">T</span><span class="special">&amp;&amp;</span> <span class="identifier">declval</span><span class="special">();</span> <span class="comment">// not used
</span></pre>
<p>
as part of the function template declaration
</p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">To</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">From</span><span class="special">&gt;</span>
<span class="identifier">decltype</span><span class="special">(</span><span class="keyword">static_cast</span><span class="special">&lt;</span><span class="identifier">To</span><span class="special">&gt;(</span><span class="identifier">declval</span><span class="special">&lt;</span><span class="identifier">From</span><span class="special">&gt;()))</span> <span class="identifier">convert</span><span class="special">(</span><span class="identifier">From</span><span class="special">&amp;&amp;);</span>
</pre>
<p>
or as part of a class template definition
</p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span><span class="special">&gt;</span> <span class="keyword">class</span> <span class="identifier">result_of</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">Fn</span><span class="special">,</span> <span class="keyword">class</span><span class="special">...</span> <span class="identifier">ArgTypes</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">result_of</span><span class="special">&lt;</span><span class="identifier">Fn</span><span class="special">(</span><span class="identifier">ArgTypes</span><span class="special">...)&gt;</span>
<span class="special">{</span>
<span class="keyword">typedef</span> <span class="identifier">decltype</span><span class="special">(</span><span class="identifier">declval</span><span class="special">&lt;</span><span class="identifier">Fn</span><span class="special">&gt;()(</span><span class="identifier">declval</span><span class="special">&lt;</span><span class="identifier">ArgTypes</span><span class="special">&gt;()...))</span> <span class="identifier">type</span><span class="special">;</span>
<span class="special">};</span>
</pre>
<p>
The role of the function template declval() is a transformation of a type T
into a value without using or evaluating this function. The name is supposed
to direct the reader's attention to the fact that the expression <code class="computeroutput"><span class="identifier">declval</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;()</span></code> is
an lvalue if and only if T is an lvalue-reference, otherwise an rvalue. To
extend the domain of this function we can do a bit better by changing its declaration
to
</p>
<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">add_rvalue_reference</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">declval</span><span class="special">();</span> <span class="comment">// not used
</span></pre>
<p>
which ensures that we can also use cv void as template parameter. The careful
reader might have noticed that <code class="computeroutput"><span class="identifier">declval</span><span class="special">()</span></code> already exists under the name create() as
part of the definition of the semantics of the type trait is_convertible in
the C==0x standard.
</p>
<p>
The provision of a new library component that allows the production of values
in unevaluated expressions is considered as important to realize constrained
templates in C++0x where concepts are not available. This extremely light-weight
function is expected to be part of the daily tool-box of the C++0x programmer.
</p>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="declval.reference"></a><a class="link" href="declval.html#declval.reference" title="Reference"> Reference </a>
</h2></div></div></div>
<p>
<code class="computeroutput"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">/</span><span class="identifier">declval</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
</p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">typename</span> <span class="identifier">add_rvalue_reference</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">declval</span><span class="special">();</span> <span class="comment">//noexcept; // as unevaluated operand
</span>
<span class="special">}</span> <span class="comment">// namespace boost
</span></pre>
<p>
The library provides the function template declval to simplify the definition
of expressions which occur as unevaluated operands.
</p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">typename</span> <span class="identifier">add_rvalue_reference</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">declval</span><span class="special">();</span>
</pre>
<p>
<span class="bold"><strong>Remarks:</strong></span> If this function is used, the program
is ill-formed.
</p>
<p>
<span class="bold"><strong>Remarks:</strong></span> The template parameter T of declval
may be an incomplete type.
</p>
<p>
<span class="bold"><strong>Example:</strong></span>
</p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">To</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">From</span><span class="special">&gt;</span>
<span class="identifier">decltype</span><span class="special">(</span><span class="keyword">static_cast</span><span class="special">&lt;</span><span class="identifier">To</span><span class="special">&gt;(</span><span class="identifier">declval</span><span class="special">&lt;</span><span class="identifier">From</span><span class="special">&gt;()))</span> <span class="identifier">convert</span><span class="special">(</span><span class="identifier">From</span><span class="special">&amp;&amp;);</span>
</pre>
<p>
Declares a function template convert which only participats in overloading
if the type From can be explicitly converted to type To.
</p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"><p><small>Last revised: September 16, 2010 at 16:19:10 GMT</small></p></td>
<td align="right"><div class="copyright-footer"></div></td>
</tr></table>
<hr>
<div class="spirit-nav"></div>
</body>
</html>

View File

@@ -1,8 +1,11 @@
// //
// boost/assert.hpp - BOOST_ASSERT(expr) // boost/assert.hpp - BOOST_ASSERT(expr)
// BOOST_ASSERT_MSG(expr, msg)
// BOOST_VERIFY(expr)
// //
// Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd.
// Copyright (c) 2007 Peter Dimov // Copyright (c) 2007 Peter Dimov
// Copyright (c) Beman Dawes 2011
// //
// Distributed under the Boost Software License, Version 1.0. (See // Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at // accompanying file LICENSE_1_0.txt or copy at
@@ -13,6 +16,16 @@
// See http://www.boost.org/libs/utility/assert.html for documentation. // See http://www.boost.org/libs/utility/assert.html for documentation.
// //
//
// Stop inspect complaining about use of 'assert':
//
// boostinspect:naassert_macro
//
//--------------------------------------------------------------------------------------//
// BOOST_ASSERT //
//--------------------------------------------------------------------------------------//
#undef BOOST_ASSERT #undef BOOST_ASSERT
#if defined(BOOST_DISABLE_ASSERTS) #if defined(BOOST_DISABLE_ASSERTS)
@@ -25,18 +38,86 @@
namespace boost namespace boost
{ {
void assertion_failed(char const * expr,
void assertion_failed(char const * expr, char const * function, char const * file, long line); // user defined char const * function, char const * file, long line); // user defined
} // namespace boost } // namespace boost
#define BOOST_ASSERT(expr) ((expr)? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) #define BOOST_ASSERT(expr) ((expr) \
? ((void)0) \
: ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
#else #else
# include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same # include <assert.h> // .h to support old libraries w/o <cassert> - effect is the same
# define BOOST_ASSERT(expr) assert(expr) # define BOOST_ASSERT(expr) assert(expr)
#endif #endif
//--------------------------------------------------------------------------------------//
// BOOST_ASSERT_MSG //
//--------------------------------------------------------------------------------------//
# undef BOOST_ASSERT_MSG
#if defined(BOOST_DISABLE_ASSERTS) || defined(NDEBUG)
#define BOOST_ASSERT_MSG(expr, msg) ((void)0)
#elif defined(BOOST_ENABLE_ASSERT_HANDLER)
#include <boost/current_function.hpp>
namespace boost
{
void assertion_failed_msg(char const * expr, char const * msg,
char const * function, char const * file, long line); // user defined
} // namespace boost
#define BOOST_ASSERT_MSG(expr, msg) ((expr) \
? ((void)0) \
: ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
#else
#ifndef BOOST_ASSERT_HPP
#define BOOST_ASSERT_HPP
#include <cstdlib>
#include <iostream>
#include <boost/current_function.hpp>
// IDE's like Visual Studio perform better if output goes to std::cout or
// some other stream, so allow user to configure output stream:
#ifndef BOOST_ASSERT_MSG_OSTREAM
# define BOOST_ASSERT_MSG_OSTREAM std::cerr
#endif
namespace boost
{
namespace assertion
{
namespace detail
{
inline void assertion_failed_msg(char const * expr, char const * msg, char const * function,
char const * file, long line)
{
BOOST_ASSERT_MSG_OSTREAM
<< "***** Internal Program Error - assertion (" << expr << ") failed in "
<< function << ":\n"
<< file << '(' << line << "): " << msg << std::endl;
std::abort();
}
} // detail
} // assertion
} // detail
#endif
#define BOOST_ASSERT_MSG(expr, msg) ((expr) \
? ((void)0) \
: ::boost::assertion::detail::assertion_failed_msg(#expr, msg, \
BOOST_CURRENT_FUNCTION, __FILE__, __LINE__))
#endif
//--------------------------------------------------------------------------------------//
// BOOST_VERIFY //
//--------------------------------------------------------------------------------------//
#undef BOOST_VERIFY #undef BOOST_VERIFY
#if defined(BOOST_DISABLE_ASSERTS) || ( !defined(BOOST_ENABLE_ASSERT_HANDLER) && defined(NDEBUG) ) #if defined(BOOST_DISABLE_ASSERTS) || ( !defined(BOOST_ENABLE_ASSERT_HANDLER) && defined(NDEBUG) )

View File

@@ -8,6 +8,8 @@
// See http://www.boost.org/libs/utility/operators.htm for documentation. // See http://www.boost.org/libs/utility/operators.htm for documentation.
// Revision History // Revision History
// 16 Dec 10 Limit warning suppression for 4284 to older versions of VC++
// (Matthew Bradbury, fixes #4432)
// 07 Aug 08 Added "euclidean" spelling. (Daniel Frey) // 07 Aug 08 Added "euclidean" spelling. (Daniel Frey)
// 03 Apr 08 Make sure "convertible to bool" is sufficient // 03 Apr 08 Make sure "convertible to bool" is sufficient
// for T::operator<, etc. (Daniel Frey) // for T::operator<, etc. (Daniel Frey)
@@ -88,7 +90,7 @@
# pragma set woff 1234 # pragma set woff 1234
#endif #endif
#if defined(BOOST_MSVC) #if BOOST_WORKAROUND(BOOST_MSVC, < 1600)
# pragma warning( disable : 4284 ) // complaint about return type of # pragma warning( disable : 4284 ) // complaint about return type of
#endif // operator-> not begin a UDT #endif // operator-> not begin a UDT

View File

@@ -4,7 +4,7 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt) // http://www.boost.org/LICENSE_1_0.txt)
// //
// See http://www.boost.org/lib/optional for documentation. // See http://www.boost.org/libs/optional for documentation.
// //
// You are welcome to contact the author at: // You are welcome to contact the author at:
// fernando_cacciola@hotmail.com // fernando_cacciola@hotmail.com

View File

@@ -0,0 +1,44 @@
// common_type.hpp ---------------------------------------------------------//
// Copyright 2010 Vicente J. Botet Escriba
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
#ifndef BOOST_TYPE_TRAITS_EXT_DECLVAL__HPP
#define BOOST_TYPE_TRAITS_EXT_DECLVAL__HPP
#include <boost/config.hpp>
//----------------------------------------------------------------------------//
#include <boost/type_traits/add_rvalue_reference.hpp>
//----------------------------------------------------------------------------//
// //
// C++03 implementation of //
// Written by Vicente J. Botet Escriba //
//~ 20.3.4 Function template declval [declval]
//~ 1 The library provides the function template declval to simplify the definition of expressions which occur as
//~ unevaluated operands.
//~ 2 Remarks: If this function is used, the program is ill-formed.
//~ 3 Remarks: The template parameter T of declval may be an incomplete type.
//~ [ Example:
//~ template <class To, class From>
//~ decltype(static_cast<To>(declval<From>())) convert(From&&);
//~ declares a function template convert which only participats in overloading if the type From can be
//~ explicitly converted to type To. For another example see class template common_type (20.7.6.6). <20>end
//~ example ]
// //
//----------------------------------------------------------------------------//
namespace boost {
template <typename T>
typename add_rvalue_reference<T>::type declval(); //noexcept; // as unevaluated operand
} // namespace boost
#endif // BOOST_TYPE_TRAITS_EXT_DECLVAL__HPP

View File

@@ -5,7 +5,7 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt) // http://www.boost.org/LICENSE_1_0.txt)
// //
// See http://www.boost.org/lib/optional for documentation. // See http://www.boost.org/libs/optional for documentation.
// //
// You are welcome to contact the author at: // You are welcome to contact the author at:
// fernando_cacciola@hotmail.com // fernando_cacciola@hotmail.com

View File

@@ -5,7 +5,7 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt) // http://www.boost.org/LICENSE_1_0.txt)
// //
// See http://www.boost.org/lib/optional for documentation. // See http://www.boost.org/libs/optional for documentation.
// //
// You are welcome to contact the author at: // You are welcome to contact the author at:
// fernando_cacciola@hotmail.com // fernando_cacciola@hotmail.com

View File

@@ -20,10 +20,63 @@
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
struct result_of<F(BOOST_RESULT_OF_ARGS)> struct tr1_result_of<F(BOOST_RESULT_OF_ARGS)>
: boost::detail::result_of_impl<F, F(BOOST_RESULT_OF_ARGS), (boost::detail::has_result_type<F>::value)> {}; : mpl::if_<
mpl::or_< is_pointer<F>, is_member_function_pointer<F> >
, boost::detail::tr1_result_of_impl<
typename remove_cv<F>::type,
typename remove_cv<F>::type(BOOST_RESULT_OF_ARGS),
(boost::detail::has_result_type<F>::value)>
, boost::detail::tr1_result_of_impl<
F,
F(BOOST_RESULT_OF_ARGS),
(boost::detail::has_result_type<F>::value)> >::type { };
#endif #endif
#if !defined(BOOST_NO_DECLTYPE) && defined(BOOST_RESULT_OF_USE_DECLTYPE)
// Uses declval following N3225 20.7.7.6 when F is not a pointer.
template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
struct result_of<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
: mpl::if_<
mpl::or_< is_pointer<F>, is_member_function_pointer<F> >
, detail::tr1_result_of_impl<
typename remove_cv<F>::type,
typename remove_cv<F>::type(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), false
>
, detail::cpp0x_result_of_impl<
F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))
>
>::type
{};
namespace detail {
template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
struct cpp0x_result_of_impl<F(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T))>
{
typedef decltype(
boost::declval<F>()(
BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_ITERATION(), declval<T, >() BOOST_PP_INTERCEPT)
)
) type;
};
} // namespace detail
#else // defined(BOOST_NO_DECLTYPE)
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
template<typename F BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
struct result_of<F(BOOST_RESULT_OF_ARGS)>
: tr1_result_of<F(BOOST_RESULT_OF_ARGS)> { };
#endif
#endif // defined(BOOST_NO_DECLTYPE)
#undef BOOST_RESULT_OF_ARGS #undef BOOST_RESULT_OF_ARGS
#if BOOST_PP_ITERATION() >= 1 #if BOOST_PP_ITERATION() >= 1
@@ -32,14 +85,14 @@ namespace detail {
template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
struct result_of_impl<R (*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false> struct tr1_result_of_impl<R (*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false>
{ {
typedef R type; typedef R type;
}; };
template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
struct result_of_impl<R (&)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false> struct tr1_result_of_impl<R (&)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs, false>
{ {
typedef R type; typedef R type;
}; };
@@ -47,7 +100,7 @@ struct result_of_impl<R (&)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),T)), FArgs
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) #if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
struct result_of_impl<R (T0::*) struct tr1_result_of_impl<R (T0::*)
(BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)), (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)),
FArgs, false> FArgs, false>
{ {
@@ -56,7 +109,7 @@ struct result_of_impl<R (T0::*)
template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
struct result_of_impl<R (T0::*) struct tr1_result_of_impl<R (T0::*)
(BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)) (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T))
const, const,
FArgs, false> FArgs, false>
@@ -66,7 +119,7 @@ struct result_of_impl<R (T0::*)
template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
struct result_of_impl<R (T0::*) struct tr1_result_of_impl<R (T0::*)
(BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)) (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T))
volatile, volatile,
FArgs, false> FArgs, false>
@@ -76,7 +129,7 @@ struct result_of_impl<R (T0::*)
template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION()) template<typename R, typename FArgs BOOST_PP_COMMA_IF(BOOST_PP_ITERATION())
BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)> BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(),typename T)>
struct result_of_impl<R (T0::*) struct tr1_result_of_impl<R (T0::*)
(BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T)) (BOOST_PP_ENUM_SHIFTED_PARAMS(BOOST_PP_ITERATION(),T))
const volatile, const volatile,
FArgs, false> FArgs, false>

View File

@@ -5,7 +5,7 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt) // http://www.boost.org/LICENSE_1_0.txt)
// //
// See http://www.boost.org/lib/optional for documentation. // See http://www.boost.org/libs/optional for documentation.
// //
// You are welcome to contact the author at: // You are welcome to contact the author at:
// fernando_cacciola@hotmail.com // fernando_cacciola@hotmail.com

View File

@@ -10,13 +10,21 @@
#define BOOST_RESULT_OF_HPP #define BOOST_RESULT_OF_HPP
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/type_traits/ice.hpp> #include <boost/preprocessor/iteration/iterate.hpp>
#include <boost/type.hpp> #include <boost/preprocessor/punctuation/comma_if.hpp>
#include <boost/preprocessor.hpp> #include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#include <boost/preprocessor/repetition/enum_shifted_params.hpp>
#include <boost/preprocessor/facilities/intercept.hpp>
#include <boost/detail/workaround.hpp> #include <boost/detail/workaround.hpp>
#include <boost/mpl/has_xxx.hpp> #include <boost/mpl/has_xxx.hpp>
#include <boost/mpl/if.hpp> #include <boost/mpl/if.hpp>
#include <boost/mpl/bool.hpp> #include <boost/mpl/bool.hpp>
#include <boost/mpl/or.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/type_traits/is_member_function_pointer.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <boost/utility/declval.hpp>
#ifndef BOOST_RESULT_OF_NUM_ARGS #ifndef BOOST_RESULT_OF_NUM_ARGS
# define BOOST_RESULT_OF_NUM_ARGS 10 # define BOOST_RESULT_OF_NUM_ARGS 10
@@ -25,13 +33,15 @@
namespace boost { namespace boost {
template<typename F> struct result_of; template<typename F> struct result_of;
template<typename F> struct tr1_result_of; // a TR1-style implementation of result_of
#if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) #if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
namespace detail { namespace detail {
BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type) BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
template<typename F, typename FArgs, bool HasResultType> struct result_of_impl; template<typename F, typename FArgs, bool HasResultType> struct tr1_result_of_impl;
template<typename F> struct cpp0x_result_of_impl;
template<typename F> template<typename F>
struct result_of_void_impl struct result_of_void_impl
@@ -51,8 +61,13 @@ struct result_of_void_impl<R (&)(void)>
typedef R type; typedef R type;
}; };
// Determine the return type of a function pointer or pointer to member.
template<typename F, typename FArgs> template<typename F, typename FArgs>
struct result_of_impl<F, FArgs, true> struct result_of_pointer
: tr1_result_of_impl<typename remove_cv<F>::type, FArgs, false> { };
template<typename F, typename FArgs>
struct tr1_result_of_impl<F, FArgs, true>
{ {
typedef typename F::result_type type; typedef typename F::result_type type;
}; };
@@ -68,7 +83,7 @@ struct result_of_nested_result : F::template result<FArgs>
{}; {};
template<typename F, typename FArgs> template<typename F, typename FArgs>
struct result_of_impl<F, FArgs, false> struct tr1_result_of_impl<F, FArgs, false>
: mpl::if_<is_function_with_no_args<FArgs>, : mpl::if_<is_function_with_no_args<FArgs>,
result_of_void_impl<F>, result_of_void_impl<F>,
result_of_nested_result<F, FArgs> >::type result_of_nested_result<F, FArgs> >::type

View File

@@ -5,7 +5,7 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt) // http://www.boost.org/LICENSE_1_0.txt)
// //
// See http://www.boost.org/lib/optional for documentation. // See http://www.boost.org/libs/optional for documentation.
// //
// You are welcome to contact the author at: // You are welcome to contact the author at:
// fernando_cacciola@hotmail.com // fernando_cacciola@hotmail.com

View File

@@ -9,6 +9,8 @@
// 23 May 2008 (Fixed operator= const issue, added initialized_value) Niels Dekker, Fernando Cacciola // 23 May 2008 (Fixed operator= const issue, added initialized_value) Niels Dekker, Fernando Cacciola
// 21 Ago 2008 (Added swap) Niels Dekker, Fernando Cacciola // 21 Ago 2008 (Added swap) Niels Dekker, Fernando Cacciola
// 20 Feb 2009 (Fixed logical const-ness issues) Niels Dekker, Fernando Cacciola // 20 Feb 2009 (Fixed logical const-ness issues) Niels Dekker, Fernando Cacciola
// 03 Apr 2010 (Added initialized<T>, suggested by Jeffrey Hellrung, fixing #3472) Niels Dekker
// 30 May 2010 (Made memset call conditional, fixing #3869) Niels Dekker
// //
#ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP #ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
#define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP #define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
@@ -20,6 +22,7 @@
// contains. More details on these issues are at libs/utility/value_init.htm // contains. More details on these issues are at libs/utility/value_init.htm
#include <boost/aligned_storage.hpp> #include <boost/aligned_storage.hpp>
#include <boost/config.hpp> // For BOOST_NO_COMPLETE_VALUE_INITIALIZATION.
#include <boost/detail/workaround.hpp> #include <boost/detail/workaround.hpp>
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/type_traits/cv_traits.hpp> #include <boost/type_traits/cv_traits.hpp>
@@ -28,10 +31,39 @@
#include <cstring> #include <cstring>
#include <new> #include <new>
#ifdef BOOST_MSVC
#pragma warning(push)
#if _MSC_VER >= 1310
// It is safe to ignore the following warning from MSVC 7.1 or higher:
// "warning C4351: new behavior: elements of array will be default initialized"
#pragma warning(disable: 4351)
// It is safe to ignore the following MSVC warning, which may pop up when T is
// a const type: "warning C4512: assignment operator could not be generated".
#pragma warning(disable: 4512)
#endif
#endif
#ifdef BOOST_NO_COMPLETE_VALUE_INITIALIZATION
// Implementation detail: The macro BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
// suggests that a workaround should be applied, because of compiler issues
// regarding value-initialization.
#define BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
#endif
// Implementation detail: The macro BOOST_DETAIL_VALUE_INIT_WORKAROUND
// switches the value-initialization workaround either on or off.
#ifndef BOOST_DETAIL_VALUE_INIT_WORKAROUND
#ifdef BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
#define BOOST_DETAIL_VALUE_INIT_WORKAROUND 1
#else
#define BOOST_DETAIL_VALUE_INIT_WORKAROUND 0
#endif
#endif
namespace boost { namespace boost {
template<class T> template<class T>
class value_initialized class initialized
{ {
private : private :
struct wrapper struct wrapper
@@ -40,6 +72,18 @@ class value_initialized
typename typename
#endif #endif
remove_const<T>::type data; remove_const<T>::type data;
wrapper()
:
data()
{
}
wrapper(T const & arg)
:
data(arg)
{
}
}; };
mutable mutable
@@ -55,30 +99,25 @@ class value_initialized
public : public :
value_initialized() initialized()
{ {
#if BOOST_DETAIL_VALUE_INIT_WORKAROUND
std::memset(&x, 0, sizeof(x)); std::memset(&x, 0, sizeof(x));
#ifdef BOOST_MSVC
#pragma warning(push)
#if _MSC_VER >= 1310
// When using MSVC 7.1 or higher, the following placement new expression may trigger warning C4345:
// "behavior change: an object of POD type constructed with an initializer of the form ()
// will be default-initialized". It is safe to ignore this warning when using value_initialized.
#pragma warning(disable: 4345)
#endif
#endif #endif
new (wrapper_address()) wrapper(); new (wrapper_address()) wrapper();
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
} }
value_initialized(value_initialized const & arg) initialized(initialized const & arg)
{ {
new (wrapper_address()) wrapper( static_cast<wrapper const &>(*(arg.wrapper_address()))); new (wrapper_address()) wrapper( static_cast<wrapper const &>(*(arg.wrapper_address())));
} }
value_initialized & operator=(value_initialized const & arg) explicit initialized(T const & arg)
{
new (wrapper_address()) wrapper(arg);
}
initialized & operator=(initialized const & arg)
{ {
// Assignment is only allowed when T is non-const. // Assignment is only allowed when T is non-const.
BOOST_STATIC_ASSERT( ! is_const<T>::value ); BOOST_STATIC_ASSERT( ! is_const<T>::value );
@@ -86,7 +125,7 @@ class value_initialized
return *this; return *this;
} }
~value_initialized() ~initialized()
{ {
wrapper_address()->wrapper::~wrapper(); wrapper_address()->wrapper::~wrapper();
} }
@@ -101,17 +140,81 @@ class value_initialized
return wrapper_address()->data; return wrapper_address()->data;
} }
void swap(value_initialized & arg) void swap(initialized & arg)
{ {
::boost::swap( this->data(), arg.data() ); ::boost::swap( this->data(), arg.data() );
} }
operator T const &() const { return this->data(); } operator T const &() const
{
return wrapper_address()->data;
}
operator T&() { return this->data(); } operator T&()
{
return wrapper_address()->data;
}
} ; } ;
template<class T>
T const& get ( initialized<T> const& x )
{
return x.data() ;
}
template<class T>
T& get ( initialized<T>& x )
{
return x.data() ;
}
template<class T>
void swap ( initialized<T> & lhs, initialized<T> & rhs )
{
lhs.swap(rhs) ;
}
template<class T>
class value_initialized
{
private :
// initialized<T> does value-initialization by default.
initialized<T> m_data;
public :
value_initialized()
:
m_data()
{ }
T const & data() const
{
return m_data.data();
}
T& data()
{
return m_data.data();
}
void swap(value_initialized & arg)
{
m_data.swap(arg.m_data);
}
operator T const &() const
{
return m_data;
}
operator T&()
{
return m_data;
}
} ;
template<class T> template<class T>
@@ -119,6 +222,7 @@ T const& get ( value_initialized<T> const& x )
{ {
return x.data() ; return x.data() ;
} }
template<class T> template<class T>
T& get ( value_initialized<T>& x ) T& get ( value_initialized<T>& x )
{ {
@@ -138,7 +242,7 @@ class initialized_value_t
template <class T> operator T() const template <class T> operator T() const
{ {
return get( value_initialized<T>() ); return initialized<T>().data();
} }
}; };
@@ -147,5 +251,8 @@ initialized_value_t const initialized_value = {} ;
} // namespace boost } // namespace boost
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
#endif #endif

View File

@@ -14,20 +14,28 @@
<p>But that doesn't mean there isn't useful stuff here. Take a look:</p> <p>But that doesn't mean there isn't useful stuff here. Take a look:</p>
<blockquote> <blockquote>
<p> <p>
<a href="utility.htm#addressof">addressof</a><br>
<a href="assert.html">assert</a><br> <a href="assert.html">assert</a><br>
<a href="base_from_member.html">base_from_member</a><br> <a href="base_from_member.html">base_from_member</a><br>
<a href="utility.htm#BOOST_BINARY">BOOST_BINARY</a><br>
<a href="call_traits.htm">call_traits</a><br> <a href="call_traits.htm">call_traits</a><br>
<a href="checked_delete.html">checked_delete</a><br> <a href="checked_delete.html">checked_delete</a><br>
<a href="compressed_pair.htm">compressed_pair</a><br> <a href="compressed_pair.htm">compressed_pair</a><br>
<a href="current_function.html">current_function</a><br> <a href="current_function.html">current_function</a><br>
<a href="enable_if.html">enable_if</a><br> <a href="doc/html/declval.html">declval</a><br>
<a href="enable_if.html">enable_if</a><br>
<a href="in_place_factories.html">in_place_factory</a><br>
<a href="iterator_adaptors.htm">iterator_adaptors</a><br> <a href="iterator_adaptors.htm">iterator_adaptors</a><br>
<a href="generator_iterator.htm">generator iterator adaptors</a><br> <a href="generator_iterator.htm">generator iterator adaptors</a><br>
<a href="utility.htm#functions_next_prior">next/prior</a><br>
<a href="utility.htm#Class_noncopyable">noncopyable</a><br>
<a href="operators.htm">operators</a><br> <a href="operators.htm">operators</a><br>
<a href="utility.htm#result_of">result_of</a><br>
<a href="swap.html">swap</a><br> <a href="swap.html">swap</a><br>
<a href="throw_exception.html">throw_exception</a><br> <a href="throw_exception.html">throw_exception</a><br>
<a href="utility.htm">utility</a><br> <a href="utility.htm">utility</a><br>
<a href="value_init.htm">value_init</a></p> <a href="value_init.htm">value_init</a>
</p>
</blockquote> </blockquote>
<hr> <hr>
<p>&copy; Copyright Beman Dawes, 2001</p> <p>&copy; Copyright Beman Dawes, 2001</p>

116
initialized_test.cpp Normal file
View File

@@ -0,0 +1,116 @@
// Copyright 2010, Niels Dekker.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Test program for boost::initialized<T>.
//
// 2 May 2010 (Created) Niels Dekker
#include <boost/utility/value_init.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <string>
namespace
{
// Typical use case for boost::initialized<T>: A generic class that
// holds a value of type T, which must be initialized by either
// value-initialization or direct-initialization.
template <class T> class key_value_pair
{
std::string m_key;
boost::initialized<T> m_value;
public:
// Value-initializes the object held by m_value.
key_value_pair() { }
// Value-initializes the object held by m_value.
explicit key_value_pair(const std::string& key)
:
m_key(key)
{
}
// Direct-initializes the object held by m_value.
key_value_pair(const std::string& key, const T& value)
:
m_key(key), m_value(value)
{
}
const T& get_value() const
{
return m_value;
}
};
// Tells whether the argument is value-initialized.
bool is_value_initialized(const int& arg)
{
return arg == 0;
}
// Tells whether the argument is value-initialized.
bool is_value_initialized(const std::string& arg)
{
return arg.empty();
}
struct foo
{
int data;
};
bool operator==(const foo& lhs, const foo& rhs)
{
return lhs.data == rhs.data;
}
// Tells whether the argument is value-initialized.
bool is_value_initialized(const foo& arg)
{
return arg.data == 0;
}
template <class T>
void test_key_value_pair(const T& magic_value)
{
// The value component of a default key_value_pair must be value-initialized.
key_value_pair<T> default_key_value_pair;
BOOST_TEST( is_value_initialized(default_key_value_pair.get_value() ) );
// The value component of a key_value_pair that only has its key explicitly specified
// must also be value-initialized.
BOOST_TEST( is_value_initialized(key_value_pair<T>("key").get_value()) );
// However, the value component of the following key_value_pair must be
// "magic_value", as it must be direct-initialized.
BOOST_TEST( key_value_pair<T>("key", magic_value).get_value() == magic_value );
}
}
// Tests boost::initialize for a fundamental type, a type with a
// user-defined constructor, and a user-defined type without
// a user-defined constructor.
int main()
{
const int magic_number = 42;
test_key_value_pair(magic_number);
const std::string magic_string = "magic value";
test_key_value_pair(magic_string);
const foo magic_foo = { 42 };
test_key_value_pair(magic_foo);
return boost::report_errors();
}

View File

@@ -0,0 +1,33 @@
// Copyright 2010, Niels Dekker.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Test program for boost::initialized<T>. Must fail to compile.
//
// Initial: 2 May 2010
#include <boost/utility/value_init.hpp>
namespace
{
void direct_initialize_from_int()
{
// Okay: initialized<T> supports direct-initialization from T.
boost::initialized<int> direct_initialized_int(1);
}
void copy_initialize_from_int()
{
// The following line should not compile, because initialized<T>
// was not intended to supports copy-initialization from T.
boost::initialized<int> copy_initialized_int = 1;
}
}
int main()
{
// This should fail to compile, so there is no need to call any function.
return 0;
}

View File

@@ -0,0 +1,37 @@
// Copyright 2010, Niels Dekker.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Test program for boost::initialized<T>. Must fail to compile.
//
// Initial: 2 May 2010
#include <boost/utility/value_init.hpp>
namespace
{
void from_value_initialized_to_initialized()
{
boost::value_initialized<int> value_initialized_int;
// Okay: initialized<T> can be initialized by value_initialized<T>.
boost::initialized<int> initialized_int(value_initialized_int);
}
void from_initialized_to_value_initialized()
{
boost::initialized<int> initialized_int(13);
// The following line should not compile, because initialized<T>
// should not be convertible to value_initialized<T>.
boost::value_initialized<int> value_initialized_int(initialized_int);
}
}
int main()
{
// This should fail to compile, so there is no need to call any function.
return 0;
}

View File

@@ -32,9 +32,13 @@ test-suite utility
[ compile result_of_test.cpp ] [ compile result_of_test.cpp ]
[ run ../shared_iterator_test.cpp ] [ run ../shared_iterator_test.cpp ]
[ run ../value_init_test.cpp ] [ run ../value_init_test.cpp ]
[ run ../value_init_workaround_test.cpp ]
[ run ../initialized_test.cpp ]
[ compile-fail ../value_init_test_fail1.cpp ] [ compile-fail ../value_init_test_fail1.cpp ]
[ compile-fail ../value_init_test_fail2.cpp ] [ compile-fail ../value_init_test_fail2.cpp ]
[ compile-fail ../value_init_test_fail3.cpp ] [ compile-fail ../value_init_test_fail3.cpp ]
[ compile-fail ../initialized_test_fail1.cpp ]
[ compile-fail ../initialized_test_fail2.cpp ]
[ run ../verify_test.cpp ] [ run ../verify_test.cpp ]
; ;

View File

@@ -5,41 +5,119 @@
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt) // http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_RESULT_OF_USE_DECLTYPE
// For more information, see http://www.boost.org/libs/utility // For more information, see http://www.boost.org/libs/utility
#include <boost/utility/result_of.hpp> #include <boost/utility/result_of.hpp>
#include <utility> #include <utility>
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/type_traits/is_same.hpp> #include <boost/type_traits/is_same.hpp>
struct int_result_type { typedef int result_type; }; struct int_result_type
{
typedef int result_type;
result_type operator()(float);
};
struct int_result_of struct int_result_of
{ {
template<typename F> struct result { typedef int type; }; template<typename F> struct result { typedef int type; };
result<int_result_of(double)>::type operator()(double);
result<const int_result_of(double)>::type operator()(double) const;
result<int_result_of()>::type operator()();
result<volatile int_result_of()>::type operator()() volatile;
}; };
struct int_result_type_and_float_result_of struct int_result_type_and_float_result_of_and_char_return
{ {
typedef int result_type; typedef int result_type;
template<typename F> struct result { typedef float type; }; template<typename F> struct result { typedef float type; };
char operator()(char);
}; };
template<typename T> template<typename T>
struct int_result_type_template { typedef int result_type; }; struct int_result_type_template
{
typedef int result_type;
result_type operator()(float);
};
template<typename T> template<typename T>
struct int_result_of_template struct int_result_of_template
{ {
template<typename F> struct result; template<typename F> struct result;
template<typename This, typename That> struct result<This(That)> { typedef int type; }; template<typename This, typename That> struct result<This(That)> { typedef int type; };
typename result<int_result_of_template<T>(double)>::type operator()(double);
typename result<const int_result_of_template<T>(double)>::type operator()(double) const;
typename result<int_result_of_template<T>(double)>::type operator()();
typename result<volatile int_result_of_template<T>(double)>::type operator()() volatile;
}; };
template<typename T> template<typename T>
struct int_result_type_and_float_result_of_template struct int_result_type_and_float_result_of_and_char_return_template
{ {
typedef int result_type; typedef int result_type;
template<typename F> struct result; template<typename F> struct result;
template<typename This, typename That> struct result<This(That)> { typedef float type; }; template<typename This, typename That> struct result<This(That)> { typedef float type; };
char operator()(char);
};
struct result_of_member_function_template
{
template<typename F> struct result;
template<typename This, typename That> struct result<This(That)> { typedef That type; };
template<class T> typename result<result_of_member_function_template(T)>::type operator()(T);
template<typename This, typename That> struct result<const This(That)> { typedef const That type; };
template<class T> typename result<const result_of_member_function_template(T)>::type operator()(T) const;
template<typename This, typename That> struct result<volatile This(That)> { typedef volatile That type; };
template<class T> typename result<volatile result_of_member_function_template(T)>::type operator()(T) volatile;
template<typename This, typename That> struct result<const volatile This(That)> { typedef const volatile That type; };
template<class T> typename result<const volatile result_of_member_function_template(T)>::type operator()(T) const volatile;
template<typename This, typename That> struct result<This(That &, That)> { typedef That & type; };
template<class T> typename result<result_of_member_function_template(T &, T)>::type operator()(T &, T);
template<typename This, typename That> struct result<This(That const &, That)> { typedef That const & type; };
template<class T> typename result<result_of_member_function_template(T const &, T)>::type operator()(T const &, T);
template<typename This, typename That> struct result<This(That volatile &, That)> { typedef That volatile & type; };
template<class T> typename result<result_of_member_function_template(T volatile &, T)>::type operator()(T volatile &, T);
template<typename This, typename That> struct result<This(That const volatile &, That)> { typedef That const volatile & type; };
template<class T> typename result<result_of_member_function_template(T const volatile &, T)>::type operator()(T const volatile &, T);
};
struct no_result_type_or_result_of
{
int operator()(double);
short operator()(double) const;
unsigned int operator()();
unsigned short operator()() volatile;
const unsigned short operator()() const volatile;
#if !defined(BOOST_NO_RVALUE_REFERENCES)
short operator()(int&&);
int operator()(int&);
long operator()(int const&);
#endif
};
template<typename T>
struct no_result_type_or_result_of_template
{
int operator()(double);
short operator()(double) const;
unsigned int operator()();
unsigned short operator()() volatile;
const unsigned short operator()() const volatile;
#if !defined(BOOST_NO_RVALUE_REFERENCES)
short operator()(int&&);
int operator()(int&);
long operator()(int const&);
#endif
}; };
struct X {}; struct X {};
@@ -60,16 +138,52 @@ int main()
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type(float)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<int_result_type(float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of(double)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<int_result_of(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const int_result_of(double)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<const int_result_of(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_and_float_result_of(char)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_template<void>(float)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_template<void>(float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of_template<void>(double)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<int_result_of_template<void>(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of_template<void>(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const int_result_of_template<void>(double)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<const int_result_of_template<void>(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_type(float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_of(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<const int_result_of(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_type_template<void>(float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_of_template<void>(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<const int_result_of_template<void>(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_of(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<volatile int_result_of(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_of_template<void>(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<volatile int_result_of_template<void>(void)>::type, void>::value));
// Prior to decltype, result_of could not deduce the return type
// nullary function objects unless they exposed a result_type.
#if !defined(BOOST_NO_DECLTYPE)
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of(void)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of(void)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of_template<void>(void)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of_template<void>(void)>::type, int>::value));
#else
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_of_template<void>(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of_template<void>(void)>::type, void>::value)); BOOST_STATIC_ASSERT((is_same<result_of<volatile int_result_of_template<void>(void)>::type, void>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_and_float_result_of_template<void>(char)>::type, int>::value)); #endif
BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_type_and_float_result_of_and_char_return(char)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<int_result_type_and_float_result_of_and_char_return_template<void>(char)>::type, int>::value));
// Prior to decltype, result_of ignored a nested result<> if
// result_type was defined. After decltype, result_of deduces the
// actual return type of the function object, ignoring both
// result<> and result_type.
#if !defined(BOOST_NO_DECLTYPE)
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_and_float_result_of_and_char_return(char)>::type, char>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_and_float_result_of_and_char_return_template<void>(char)>::type, char>::value));
#else
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_and_float_result_of_and_char_return(char)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<int_result_type_and_float_result_of_and_char_return_template<void>(char)>::type, int>::value));
#endif
BOOST_STATIC_ASSERT((is_same<result_of<func_ptr(char, float)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<func_ptr(char, float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<func_ref(char, float)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<func_ref(char, float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<func_ptr_0()>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<func_ptr_0()>::type, int>::value));
@@ -81,5 +195,62 @@ int main()
BOOST_STATIC_ASSERT((is_same<result_of<mem_func_ptr_0(X)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<mem_func_ptr_0(X)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<func_ptr(void)>::type, int>::value)); BOOST_STATIC_ASSERT((is_same<result_of<func_ptr(void)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ptr(char, float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ref(char, float)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ptr_0()>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ref_0()>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr(X,char)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr_c(X,char)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr_v(X,char)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr_cv(X,char)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<mem_func_ptr_0(X)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<func_ptr(void)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(double)>::type, double>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const result_of_member_function_template(double)>::type, const double>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile result_of_member_function_template(double)>::type, volatile double>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const volatile result_of_member_function_template(double)>::type, const volatile double>::value));
BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(int &, int)>::type, int &>::value));
BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(int const &, int)>::type, int const &>::value));
BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(int volatile &, int)>::type, int volatile &>::value));
BOOST_STATIC_ASSERT((is_same<result_of<result_of_member_function_template(int const volatile &, int)>::type, int const volatile &>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(double)>::type, double>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<const result_of_member_function_template(double)>::type, const double>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<volatile result_of_member_function_template(double)>::type, volatile double>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<const volatile result_of_member_function_template(double)>::type, const volatile double>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(int &, int)>::type, int &>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(int const &, int)>::type, int const &>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(int volatile &, int)>::type, int volatile &>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<result_of_member_function_template(int const volatile &, int)>::type, int const volatile &>::value));
typedef int (*pf_t)(int);
BOOST_STATIC_ASSERT((is_same<result_of<pf_t(int)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<pf_t const(int)>::type,int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<pf_t(int)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<tr1_result_of<pf_t const(int)>::type,int>::value));
#if !defined(BOOST_NO_DECLTYPE)
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(void)>::type, unsigned int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const no_result_type_or_result_of(double)>::type, short>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile no_result_type_or_result_of(void)>::type, unsigned short>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const volatile no_result_type_or_result_of(void)>::type, const unsigned short>::value));
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of_template<void>(double)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of_template<void>(void)>::type, unsigned int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const no_result_type_or_result_of_template<void>(double)>::type, short>::value));
BOOST_STATIC_ASSERT((is_same<result_of<volatile no_result_type_or_result_of_template<void>(void)>::type, unsigned short>::value));
BOOST_STATIC_ASSERT((is_same<result_of<const volatile no_result_type_or_result_of_template<void>(void)>::type, const unsigned short>::value));
#if !defined(BOOST_NO_RVALUE_REFERENCES)
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(int&&)>::type, short>::value));
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(int&)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of(int const&)>::type, long>::value));
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of_template<void>(int&&)>::type, short>::value));
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of_template<void>(int&)>::type, int>::value));
BOOST_STATIC_ASSERT((is_same<result_of<no_result_type_or_result_of_template<void>(int const&)>::type, long>::value));
#endif
#endif
return 0; return 0;
} }

View File

@@ -151,35 +151,95 @@ void f() {
<code>result_of&lt;F(T1, T2, ..., <code>result_of&lt;F(T1, T2, ...,
T<em>N</em>)&gt;::type</code> defines the result type T<em>N</em>)&gt;::type</code> defines the result type
of the expression <code>f(t1, t2, of the expression <code>f(t1, t2,
...,t<em>N</em>)</code>. The implementation permits ...,t<em>N</em>)</code>. This implementation permits
the type <code>F</code> to be a function pointer, the type <code>F</code> to be a function pointer,
function reference, member function pointer, or class function reference, member function pointer, or class
type. When <code>F</code> is a class type with a type. By default, <em>N</em> may be any value between 0 and
10. To change the upper limit, define the macro
<code>BOOST_RESULT_OF_NUM_ARGS</code> to the maximum
value for <em>N</em>. Class template <code>result_of</code>
resides in the header <code>&lt;<a
href="../../boost/utility/result_of.hpp">boost/utility/result_of.hpp</a>&gt;</code>.</p>
<p>If your compiler supports <code>decltype</code>,
then you can enable automatic result type deduction by
defining the macro <code>BOOST_RESULT_OF_USE_DECLTYPE</code>,
as in the following example.</p>
<blockquote>
<pre>#define BOOST_RESULT_OF_USE_DECLTYPE
#include &lt;boost/utility/result_of.hpp&gt;
struct functor {
template&lt;class T&gt;
T operator()(T x)
{
return x;
}
};
typedef boost::result_of&lt;
functor(int)
&gt;::type type;</pre>
</blockquote>
<p>If <code>decltype</code> is not enabled,
then automatic result type deduction of function
objects is not possible. Instead, <code>result_of</code>
uses the following protocol to allow the programmer to
specify a type. When <code>F</code> is a class type with a
member type <code>result_type</code>, member type <code>result_type</code>,
<code>result_of&lt;F(T1, T2, ..., <code>result_of&lt;F(T1, T2, ...,
T<em>N</em>)&gt;</code> is T<em>N</em>)&gt;</code> is
<code>F::result_type</code>. Otherwise, <code>F::result_type</code>. When <code>F</code> does
not contain <code>result_type</code>,
<code>result_of&lt;F(T1, T2, ..., <code>result_of&lt;F(T1, T2, ...,
T<em>N</em>)&gt;</code> is <code>F::result&lt;F(T1, T<em>N</em>)&gt;</code> is <code>F::result&lt;F(T1,
T2, ..., T<em>N</em>)&gt;::type</code> when T2, ..., T<em>N</em>)&gt;::type</code> when
<code><em>N</em> &gt; 0</code> or <code>void</code> <code><em>N</em> &gt; 0</code> or <code>void</code>
when <code><em>N</em> = 0</code>. For additional when <code><em>N</em> = 0</code>. Note that it is the
information about <code>result_of</code>, see the responsibility of the programmer to ensure that
C++ Library Technical Report, <a function objects accurately advertise their result
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">N1836</a>, type via this protocol, as in the following
or, for motivation and design rationale, the <code>result_of</code> <a example.</p>
href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1454.html">proposal</a>.</p>
<p>Class template <code>result_of</code> resides in <blockquote>
the header <code>&lt;<a <pre>struct functor {
href="../../boost/utility/result_of.hpp">boost/utility/result_of.hpp</a>&gt;</code>. By template&lt;class&gt; struct result;
default, <em>N</em> may be any value between 0 and
10. To change the upper limit, define the macro template&lt;class F, class T&gt;
<code>BOOST_RESULT_OF_NUM_ARGS</code> to the maximum struct result&lt;F(T)&gt; {
value for <em>N</em>.</p> typedef T type;
};
template&lt;class T&gt;
T operator()(T x)
{
return x;
}
};
typedef boost::result_of&lt;
functor(int)
&gt;::type type;</pre>
</blockquote>
<a name="BOOST_NO_RESULT_OF"></a> <a name="BOOST_NO_RESULT_OF"></a>
<p>This implementation of <code>result_of</code> requires class template partial specialization, the ability to parse function types properly, and support for SFINAE. If <code>result_of</code> is not supported by your compiler, including the header <code>boost/utility/result_of.hpp</code> will define the macro <code>BOOST_NO_RESULT_OF</code>. Contributed by Doug Gregor.</p> <p>This implementation of <code>result_of</code>
requires class template partial specialization, the
ability to parse function types properly, and support
for SFINAE. If <code>result_of</code> is not supported
by your compiler, including the header
<code>boost/utility/result_of.hpp</code> will
define the macro <code>BOOST_NO_RESULT_OF</code>.</p>
<p>For additional information
about <code>result_of</code>, see the C++ Library
Technical Report,
<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">N1836</a>,
or, for motivation and design rationale,
the <code>result_of</code> <a href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1454.html">proposal</a>.</p>
Contributed by Doug Gregor.</p>
<h2>Class templates for the Base-from-Member Idiom</h2> <h2>Class templates for the Base-from-Member Idiom</h2>
<p>See <a href="base_from_member.html">separate documentation</a>.</p> <p>See <a href="base_from_member.html">separate documentation</a>.</p>

View File

@@ -33,6 +33,7 @@
<ul> <ul>
<li><a href="#val_init"><code>template class value_initialized&lt;T&gt;</code></a></li> <li><a href="#val_init"><code>template class value_initialized&lt;T&gt;</code></a></li>
<li><a href="#initialized"><code>template class initialized&lt;T&gt;</code></a></li>
<li><a href="#initialized_value"><code>initialized_value</code></a></li> <li><a href="#initialized_value"><code>initialized_value</code></a></li>
</ul> </ul>
@@ -123,6 +124,12 @@ constructed by the following declaration:
</pre> </pre>
</p> </p>
<p> <p>
The template <a href="#initialized"><code>initialized</code></a>
offers both value-initialization and direct-initialization.
It is especially useful as a data member type, allowing the very same object
to be either direct-initialized or value-initialized.
</p>
<p>
The <code>const</code> object <a href="#initialized_value"><code>initialized_value</code></a> The <code>const</code> object <a href="#initialized_value"><code>initialized_value</code></a>
allows value-initializing a variable as follows: allows value-initializing a variable as follows:
<pre> <pre>
@@ -216,37 +223,65 @@ it <em>may</em> in practice still be left uninitialized, because of those
compiler issues! It's hard to make a general statement on what those issues compiler issues! It's hard to make a general statement on what those issues
are like, because they depend on the compiler you are using, its version number, are like, because they depend on the compiler you are using, its version number,
and the type of object you would like to have value-initialized. and the type of object you would like to have value-initialized.
Compilers usually support value-initialization for built-in types properly. All compilers we have tested so far support value-initialization for arithmetic types properly.
But objects of user-defined types that involve <em>aggregates</em> may <em>in some cases</em> However, various compilers may leave some types of <em>aggregates</em> uninitialized, when they
be partially, or even entirely left uninitialized, when they should be value-initialized. should be value-initialized. Value-initialization of objects of a pointer-to-member type may also
go wrong on various compilers.
</p> </p>
<p> <p>
We have encountered issues regarding value-initialization on compilers by At the moment of writing, May 2010, the following reported issues regarding
Microsoft, Sun, Borland, and GNU. Here is a list of bug reports on those issues: value-initialization are still there in current compiler releases:
<table summary="Compiler bug reports regarding value-initialization" border="0" cellpadding="7" cellspacing="1" > <ul>
<tr><td> <li>
<a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100744"> <a href="https://connect.microsoft.com/VisualStudio/feedback/details/100744">
Microsoft Feedback ID 100744 - Value-initialization in new-expression</a> Microsoft Visual Studio Feedback ID 100744, Value-initialization in new-expression</a>
<br>Reported by Pavel Kuznetsov (MetaCommunications Engineering), 2005-07-28 <br>Reported by Pavel Kuznetsov (MetaCommunications Engineering), 2005
<br> </li><li>
<a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30111"> <a href="http://connect.microsoft.com/VisualStudio/feedback/details/484295">
GCC Bug 30111 - Value-initialization of POD base class doesn't initialize members</a> Microsoft Visual Studio Feedback ID 484295, VC++ does not value-initialize members of derived classes without user-declared constructor</a>
<br>Reported by Jonathan Wakely, 2006-12-07 <br>Reported by Sylvester Hesp, 2009
<br> </li><li>
<a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33916"> <a href="https://connect.microsoft.com/VisualStudio/feedback/details/499606">
GCC Bug 33916 - Default constructor fails to initialize array members</a> Microsoft Visual Studio Feedback ID 499606, Presence of copy constructor breaks member class initialization</a>
<br>Reported by Michael Elizabeth Chastain, 2007-10-26 <br>Reported by Alex Vakulenko, 2009
<br> </li><li>
<a href="http://qc.codegear.com/wc/qcmain.aspx?d=51854"> <a href="http://qc.embarcadero.com/wc/qcmain.aspx?d=83751">
Borland Report 51854 - Value-initialization: POD struct should be zero-initialized</a> Embarcadero/C++Builder Report 83751, Value-initialization: arrays should have each element value-initialized</a>
<br>Reported by Niels Dekker (LKEB, Leiden University Medical Center), 2007-09-11 <br>Reported by Niels Dekker (LKEB), 2010
<br> </li><li>
</td></tr></table> <a href="http://qc.embarcadero.com/wc/qcmain.aspx?d=83851">
Embarcadero/C++Builder Report 83851, Value-initialized temporary triggers internal backend error C1798</a>
<br>Reported by Niels Dekker, 2010
</li><li>
<a href="http://qc.embarcadero.com/wc/qcmain.aspx?d=84279">
Embarcadero/C++Builder Report 84279, Internal compiler error (F1004), value-initializing member function pointer by "new T()"</a>
<br>Reported by Niels Dekker, 2010
</li><li>
Sun CR 6947016, Sun 5.10 may fail to value-initialize an object of a non-POD aggregate.
<br>Reported to Steve Clamage by Niels Dekker, 2010
</li><li>
IBM's XL V10.1 and V11.1 may fail to value-initialize a temporary of a non-POD aggregate.
<br>Reported to Michael Wong by Niels Dekker, 2010
</li><li>
Intel support issue 589832, Attempt to value-initialize pointer-to-member triggers internal error
on Intel 11.1.
<br>Reported by John Maddock, 2010
</li>
</ul>
Note that all known GCC issues regarding value-initialization are
fixed with GCC version 4.4, including
<a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30111">GCC Bug 30111</a>.
Clang also has completely implemented value-initialization, as far as we know,
now that <a href="http://llvm.org/bugs/show_bug.cgi?id=7139">Clang Bug 7139</a> is fixed.
</p><p> </p><p>
New versions of <code>value_initialized</code> New versions of <code>value_initialized</code>
(Boost release version 1.35 or higher) (Boost release version 1.35 or higher)
offer a workaround to these issues: <code>value_initialized</code> will now clear offer a workaround to these issues: <code>value_initialized</code> may now clear
its internal data, prior to constructing the object that it contains. its internal data, prior to constructing the object that it contains. It will do
so for those compilers that need to have such a workaround, based on the
<a href="../config/doc/html/boost_config/boost_macro_reference.html#boost_config.boost_macro_reference.macros_that_describe_defects"
>compiler defect macro</a> BOOST_NO_COMPLETE_VALUE_INITIALIZATION.
</p> </p>
<h2><a name="types"></a>Types and objects</h2> <h2><a name="types"></a>Types and objects</h2>
@@ -340,6 +375,52 @@ the wrapped object is always performed with the <code>get()</code> idiom:</p>
<pre>value_initialized&lt;int&gt; x ;<br>get(x) = 1 ; // OK<br><br>value_initialized&lt;int const&gt; cx ;<br>get(x) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized&lt;int&gt; const x_c ;<br>get(x_c) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized&lt;int const&gt; const cx_c ;<br>get(cx_c) = 1 ; // ERROR: Cannot modify a const object<br></pre> <pre>value_initialized&lt;int&gt; x ;<br>get(x) = 1 ; // OK<br><br>value_initialized&lt;int const&gt; cx ;<br>get(x) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized&lt;int&gt; const x_c ;<br>get(x_c) = 1 ; // ERROR: Cannot modify a const object<br><br>value_initialized&lt;int const&gt; const cx_c ;<br>get(cx_c) = 1 ; // ERROR: Cannot modify a const object<br></pre>
<h2><a name="initialized"><code>template class initialized&lt;T&gt;</code></a></h2>
<pre>namespace boost {<br><br>template&lt;class T&gt;<br>class initialized<br>{
<br> public :
<br> initialized() : x() {}
<br> explicit initialized(T const &amp; arg) : x(arg) {}
<br> operator T const &amp;() const;
<br> operator T&amp;();
<br> T const &amp;data() const;
<br> T&amp; data();
<br> void swap( value_initialized&lt;T&gt;&amp; );
<br>
<br> private :
<br> <i>unspecified</i> x ;
<br>} ;
<br>
<br>template&lt;class T&gt;
<br>T const&amp; get ( initialized&lt;T&gt; const&amp; x );
<br>
<br>template&lt;class T&gt;
<br>T&amp; get ( initialized&lt;T&gt;&amp; x );
<br>
<br>} // namespace boost
<br></pre>
The template class <code>boost::initialized&lt;T&gt;</code> supports both value-initialization
and direct-initialization, so its interface is a superset of the interface
of <code>value_initialized&lt;T&gt;</code>: Its default-constructor
value-initializes the wrapped object just like the default-constructor of
<code>value_initialized&lt;T&gt;</code>, but <code>boost::initialized&lt;T&gt;</code>
also offers an extra <code>explicit</code>
constructor, which direct-initializes the wrapped object by the specified value.
<p>
<code>initialized&lt;T&gt;</code> is especially useful when the wrapped
object must be either value-initialized or direct-initialized, depending on
runtime conditions. For example, <code>initialized&lt;T&gt;</code> could
hold the value of a data member that may be value-initialized by some
constructors, and direct-initialized by others.
On the other hand, if it is known beforehand that the
object must <i>always</i> be value-initialized, <code>value_initialized&lt;T&gt;</code>
may be preferable. And if the object must always be
direct-initialized, none of the two wrappers really needs to be used.
</p>
<h2><a name="initialized_value"><code>initialized_value</code></a></h2> <h2><a name="initialized_value"><code>initialized_value</code></a></h2>
<pre> <pre>
@@ -399,6 +480,9 @@ Special thanks to Bj&ouml;rn Karlsson who carefully edited and completed this do
<p>value_initialized was reimplemented by Fernando Cacciola and Niels Dekker <p>value_initialized was reimplemented by Fernando Cacciola and Niels Dekker
for Boost release version 1.35 (2008), offering a workaround to various compiler issues. for Boost release version 1.35 (2008), offering a workaround to various compiler issues.
</p> </p>
<p><code>boost::initialized</code> was very much inspired by feedback from Edward Diener and
Jeffrey Hellrung.
</p>
<p>initialized_value was written by Niels Dekker, and added to Boost release version 1.36 (2008). <p>initialized_value was written by Niels Dekker, and added to Boost release version 1.36 (2008).
</p> </p>
<p>Developed by <a href="mailto:fernando_cacciola@hotmail.com">Fernando Cacciola</a>, <p>Developed by <a href="mailto:fernando_cacciola@hotmail.com">Fernando Cacciola</a>,
@@ -407,9 +491,9 @@ for Boost release version 1.35 (2008), offering a workaround to various compiler
</p> </p>
<hr> <hr>
<p>Revised 03 October 2009</p> <p>Revised 30 May 2010</p>
<p>&copy; Copyright Fernando Cacciola, 2002, 2009.</p> <p>&copy; Copyright Fernando Cacciola, 2002 - 2010.</p>
<p>Distributed under the Boost Software License, Version 1.0. See <p>Distributed under the Boost Software License, Version 1.0. See
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p> <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>

View File

@@ -22,7 +22,7 @@
#pragma hdrstop #pragma hdrstop
#endif #endif
#include "boost/test/minimal.hpp" #include <boost/detail/lightweight_test.hpp>
// //
// Sample POD type // Sample POD type
@@ -215,7 +215,7 @@ template<class T>
void check_initialized_value ( T const& y ) void check_initialized_value ( T const& y )
{ {
T initializedValue = boost::initialized_value ; T initializedValue = boost::initialized_value ;
BOOST_CHECK ( y == initializedValue ) ; BOOST_TEST ( y == initializedValue ) ;
} }
#ifdef __BORLANDC__ #ifdef __BORLANDC__
@@ -245,128 +245,125 @@ void check_initialized_value( NonPOD const& )
template<class T> template<class T>
bool test ( T const& y, T const& z ) bool test ( T const& y, T const& z )
{ {
const boost::unit_test::counter_t counter_before_test = boost::minimal_test::errors_counter(); const int errors_before_test = boost::detail::test_errors();
check_initialized_value(y); check_initialized_value(y);
boost::value_initialized<T> x ; boost::value_initialized<T> x ;
BOOST_CHECK ( y == x ) ; BOOST_TEST ( y == x ) ;
BOOST_CHECK ( y == boost::get(x) ) ; BOOST_TEST ( y == boost::get(x) ) ;
static_cast<T&>(x) = z ; static_cast<T&>(x) = z ;
boost::get(x) = z ; boost::get(x) = z ;
BOOST_CHECK ( x == z ) ; BOOST_TEST ( x == z ) ;
boost::value_initialized<T> const x_c ; boost::value_initialized<T> const x_c ;
BOOST_CHECK ( y == x_c ) ; BOOST_TEST ( y == x_c ) ;
BOOST_CHECK ( y == boost::get(x_c) ) ; BOOST_TEST ( y == boost::get(x_c) ) ;
T& x_c_ref = const_cast<T&>( boost::get(x_c) ) ; T& x_c_ref = const_cast<T&>( boost::get(x_c) ) ;
x_c_ref = z ; x_c_ref = z ;
BOOST_CHECK ( x_c == z ) ; BOOST_TEST ( x_c == z ) ;
boost::value_initialized<T> const copy1 = x; boost::value_initialized<T> const copy1 = x;
BOOST_CHECK ( boost::get(copy1) == boost::get(x) ) ; BOOST_TEST ( boost::get(copy1) == boost::get(x) ) ;
boost::value_initialized<T> copy2; boost::value_initialized<T> copy2;
copy2 = x; copy2 = x;
BOOST_CHECK ( boost::get(copy2) == boost::get(x) ) ; BOOST_TEST ( boost::get(copy2) == boost::get(x) ) ;
boost::shared_ptr<boost::value_initialized<T> > ptr( new boost::value_initialized<T> ); boost::shared_ptr<boost::value_initialized<T> > ptr( new boost::value_initialized<T> );
BOOST_CHECK ( y == *ptr ) ; BOOST_TEST ( y == *ptr ) ;
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1300) #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
boost::value_initialized<T const> cx ; boost::value_initialized<T const> cx ;
BOOST_CHECK ( y == cx ) ; BOOST_TEST ( y == cx ) ;
BOOST_CHECK ( y == boost::get(cx) ) ; BOOST_TEST ( y == boost::get(cx) ) ;
boost::value_initialized<T const> const cx_c ; boost::value_initialized<T const> const cx_c ;
BOOST_CHECK ( y == cx_c ) ; BOOST_TEST ( y == cx_c ) ;
BOOST_CHECK ( y == boost::get(cx_c) ) ; BOOST_TEST ( y == boost::get(cx_c) ) ;
#endif #endif
return boost::minimal_test::errors_counter() == counter_before_test ; return boost::detail::test_errors() == errors_before_test ;
} }
int test_main(int, char **) int main(int, char **)
{ {
BOOST_CHECK ( test( 0,1234 ) ) ; BOOST_TEST ( test( 0,1234 ) ) ;
BOOST_CHECK ( test( 0.0,12.34 ) ) ; BOOST_TEST ( test( 0.0,12.34 ) ) ;
BOOST_CHECK ( test( POD(0,0,0.0), POD('a',1234,56.78f) ) ) ; BOOST_TEST ( test( POD(0,0,0.0), POD('a',1234,56.78f) ) ) ;
BOOST_CHECK ( test( NonPOD( std::string() ), NonPOD( std::string("something") ) ) ) ; BOOST_TEST ( test( NonPOD( std::string() ), NonPOD( std::string("something") ) ) ) ;
NonPOD NonPOD_object( std::string("NonPOD_object") ); NonPOD NonPOD_object( std::string("NonPOD_object") );
BOOST_CHECK ( test<NonPOD *>( 0, &NonPOD_object ) ) ; BOOST_TEST ( test<NonPOD *>( 0, &NonPOD_object ) ) ;
AggregatePODStruct zeroInitializedAggregatePODStruct = { 0.0f, '\0', 0 }; AggregatePODStruct zeroInitializedAggregatePODStruct = { 0.0f, '\0', 0 };
AggregatePODStruct nonZeroInitializedAggregatePODStruct = { 1.25f, 'a', -1 }; AggregatePODStruct nonZeroInitializedAggregatePODStruct = { 1.25f, 'a', -1 };
BOOST_CHECK ( test(zeroInitializedAggregatePODStruct, nonZeroInitializedAggregatePODStruct) ); BOOST_TEST ( test(zeroInitializedAggregatePODStruct, nonZeroInitializedAggregatePODStruct) );
StringAndInt stringAndInt0; StringAndInt stringAndInt0;
StringAndInt stringAndInt1; StringAndInt stringAndInt1;
stringAndInt0.i = 0; stringAndInt0.i = 0;
stringAndInt1.i = 1; stringAndInt1.i = 1;
stringAndInt1.s = std::string("1"); stringAndInt1.s = std::string("1");
BOOST_CHECK ( test(stringAndInt0, stringAndInt1) ); BOOST_TEST ( test(stringAndInt0, stringAndInt1) );
StructWithDestructor structWithDestructor0; StructWithDestructor structWithDestructor0;
StructWithDestructor structWithDestructor1; StructWithDestructor structWithDestructor1;
structWithDestructor0.i = 0; structWithDestructor0.i = 0;
structWithDestructor1.i = 1; structWithDestructor1.i = 1;
BOOST_CHECK ( test(structWithDestructor0, structWithDestructor1) ); BOOST_TEST ( test(structWithDestructor0, structWithDestructor1) );
StructWithVirtualFunction structWithVirtualFunction0; StructWithVirtualFunction structWithVirtualFunction0;
StructWithVirtualFunction structWithVirtualFunction1; StructWithVirtualFunction structWithVirtualFunction1;
structWithVirtualFunction0.i = 0; structWithVirtualFunction0.i = 0;
structWithVirtualFunction1.i = 1; structWithVirtualFunction1.i = 1;
BOOST_CHECK ( test(structWithVirtualFunction0, structWithVirtualFunction1) ); BOOST_TEST ( test(structWithVirtualFunction0, structWithVirtualFunction1) );
DerivedFromAggregatePODStruct derivedFromAggregatePODStruct0; DerivedFromAggregatePODStruct derivedFromAggregatePODStruct0;
DerivedFromAggregatePODStruct derivedFromAggregatePODStruct1; DerivedFromAggregatePODStruct derivedFromAggregatePODStruct1;
static_cast<AggregatePODStruct &>(derivedFromAggregatePODStruct0) = zeroInitializedAggregatePODStruct; static_cast<AggregatePODStruct &>(derivedFromAggregatePODStruct0) = zeroInitializedAggregatePODStruct;
static_cast<AggregatePODStruct &>(derivedFromAggregatePODStruct1) = nonZeroInitializedAggregatePODStruct; static_cast<AggregatePODStruct &>(derivedFromAggregatePODStruct1) = nonZeroInitializedAggregatePODStruct;
BOOST_CHECK ( test(derivedFromAggregatePODStruct0, derivedFromAggregatePODStruct1) ); BOOST_TEST ( test(derivedFromAggregatePODStruct0, derivedFromAggregatePODStruct1) );
AggregatePODStructWrapper aggregatePODStructWrapper0; AggregatePODStructWrapper aggregatePODStructWrapper0;
AggregatePODStructWrapper aggregatePODStructWrapper1; AggregatePODStructWrapper aggregatePODStructWrapper1;
aggregatePODStructWrapper0.dataMember = zeroInitializedAggregatePODStruct; aggregatePODStructWrapper0.dataMember = zeroInitializedAggregatePODStruct;
aggregatePODStructWrapper1.dataMember = nonZeroInitializedAggregatePODStruct; aggregatePODStructWrapper1.dataMember = nonZeroInitializedAggregatePODStruct;
BOOST_CHECK ( test(aggregatePODStructWrapper0, aggregatePODStructWrapper1) ); BOOST_TEST ( test(aggregatePODStructWrapper0, aggregatePODStructWrapper1) );
ArrayOfBytes zeroInitializedArrayOfBytes = { 0 }; ArrayOfBytes zeroInitializedArrayOfBytes = { 0 };
boost::value_initialized<ArrayOfBytes> valueInitializedArrayOfBytes; boost::value_initialized<ArrayOfBytes> valueInitializedArrayOfBytes;
BOOST_CHECK (std::memcmp(get(valueInitializedArrayOfBytes), zeroInitializedArrayOfBytes, sizeof(ArrayOfBytes)) == 0); BOOST_TEST (std::memcmp(get(valueInitializedArrayOfBytes), zeroInitializedArrayOfBytes, sizeof(ArrayOfBytes)) == 0);
boost::value_initialized<ArrayOfBytes> valueInitializedArrayOfBytes2; boost::value_initialized<ArrayOfBytes> valueInitializedArrayOfBytes2;
valueInitializedArrayOfBytes2 = valueInitializedArrayOfBytes; valueInitializedArrayOfBytes2 = valueInitializedArrayOfBytes;
BOOST_CHECK (std::memcmp(get(valueInitializedArrayOfBytes), get(valueInitializedArrayOfBytes2), sizeof(ArrayOfBytes)) == 0); BOOST_TEST (std::memcmp(get(valueInitializedArrayOfBytes), get(valueInitializedArrayOfBytes2), sizeof(ArrayOfBytes)) == 0);
boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester1; boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester1;
BOOST_CHECK ( ! get(copyFunctionCallTester1).is_copy_constructed); BOOST_TEST ( ! get(copyFunctionCallTester1).is_copy_constructed);
BOOST_CHECK ( ! get(copyFunctionCallTester1).is_assignment_called); BOOST_TEST ( ! get(copyFunctionCallTester1).is_assignment_called);
boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester2 = boost::value_initialized<CopyFunctionCallTester>(copyFunctionCallTester1); boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester2 = boost::value_initialized<CopyFunctionCallTester>(copyFunctionCallTester1);
BOOST_CHECK ( get(copyFunctionCallTester2).is_copy_constructed); BOOST_TEST ( get(copyFunctionCallTester2).is_copy_constructed);
BOOST_CHECK ( ! get(copyFunctionCallTester2).is_assignment_called); BOOST_TEST ( ! get(copyFunctionCallTester2).is_assignment_called);
boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester3; boost::value_initialized<CopyFunctionCallTester> copyFunctionCallTester3;
copyFunctionCallTester3 = boost::value_initialized<CopyFunctionCallTester>(copyFunctionCallTester1); copyFunctionCallTester3 = boost::value_initialized<CopyFunctionCallTester>(copyFunctionCallTester1);
BOOST_CHECK ( ! get(copyFunctionCallTester3).is_copy_constructed); BOOST_TEST ( ! get(copyFunctionCallTester3).is_copy_constructed);
BOOST_CHECK ( get(copyFunctionCallTester3).is_assignment_called); BOOST_TEST ( get(copyFunctionCallTester3).is_assignment_called);
boost::value_initialized<SwapFunctionCallTester> swapFunctionCallTester1; boost::value_initialized<SwapFunctionCallTester> swapFunctionCallTester1;
boost::value_initialized<SwapFunctionCallTester> swapFunctionCallTester2; boost::value_initialized<SwapFunctionCallTester> swapFunctionCallTester2;
get(swapFunctionCallTester1).data = 1; get(swapFunctionCallTester1).data = 1;
get(swapFunctionCallTester2).data = 2; get(swapFunctionCallTester2).data = 2;
boost::swap(swapFunctionCallTester1, swapFunctionCallTester2); boost::swap(swapFunctionCallTester1, swapFunctionCallTester2);
BOOST_CHECK( get(swapFunctionCallTester1).data == 2 ); BOOST_TEST( get(swapFunctionCallTester1).data == 2 );
BOOST_CHECK( get(swapFunctionCallTester2).data == 1 ); BOOST_TEST( get(swapFunctionCallTester2).data == 1 );
BOOST_CHECK( get(swapFunctionCallTester1).is_custom_swap_called ); BOOST_TEST( get(swapFunctionCallTester1).is_custom_swap_called );
BOOST_CHECK( get(swapFunctionCallTester2).is_custom_swap_called ); BOOST_TEST( get(swapFunctionCallTester2).is_custom_swap_called );
return 0; return boost::report_errors();
} }
unsigned int expected_failures = 0;

View File

@@ -0,0 +1,144 @@
// Copyright 2010, Niels Dekker.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Test program for the boost::value_initialized<T> workaround.
//
// 17 June 2010 (Created) Niels Dekker
// Switch the workaround off, before inluding "value_init.hpp".
#define BOOST_DETAIL_VALUE_INIT_WORKAROUND 0
#include <boost/utility/value_init.hpp>
#include <iostream> // For cout.
#include <cstdlib> // For EXIT_SUCCESS and EXIT_FAILURE.
namespace
{
struct empty_struct
{
};
// A POD aggregate struct derived from an empty struct.
// Similar to struct Foo1 from Microsoft Visual C++ bug report 484295,
// "VC++ does not value-initialize members of derived classes without
// user-declared constructor", reported in 2009 by Sylvester Hesp:
// https://connect.microsoft.com/VisualStudio/feedback/details/484295
struct derived_struct: empty_struct
{
int data;
};
bool is_value_initialized(const derived_struct& arg)
{
return arg.data == 0;
}
class virtual_destructor_holder
{
public:
int i;
virtual ~virtual_destructor_holder()
{
}
};
bool is_value_initialized(const virtual_destructor_holder& arg)
{
return arg.i == 0;
}
// Equivalent to the Stats class from GCC Bug 33916,
// "Default constructor fails to initialize array members", reported in 2007 by
// Michael Elizabeth Chastain: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33916
// and fixed for GCC 4.2.4.
class private_int_array_pair
{
friend bool is_value_initialized(const private_int_array_pair& arg);
private:
int first[12];
int second[12];
};
bool is_value_initialized(const private_int_array_pair& arg)
{
for ( unsigned i = 0; i < 12; ++i)
{
if ( (arg.first[i] != 0) || (arg.second[i] != 0) )
{
return false;
}
}
return true;
}
template <typename T>
bool is_value_initialized(const T(& arg)[2])
{
return
is_value_initialized(arg[0]) &&
is_value_initialized(arg[1]);
}
template <typename T>
bool is_value_initialized(const boost::value_initialized<T>& arg)
{
return is_value_initialized(arg.data());
}
// Returns zero when the specified object is value-initializated, and one otherwise.
// Prints a message to standard output if the value-initialization has failed.
template <class T>
unsigned failed_to_value_initialized(const T& object, const char *const object_name)
{
if ( is_value_initialized(object) )
{
return 0u;
}
else
{
std::cout << "Note: Failed to value-initialize " << object_name << '.' << std::endl;
return 1u;
}
}
// A macro that passed both the name and the value of the specified object to
// the function above here.
#define FAILED_TO_VALUE_INITIALIZE(value) failed_to_value_initialized(value, #value)
// Equivalent to the dirty_stack() function from GCC Bug 33916,
// "Default constructor fails to initialize array members", reported in 2007 by
// Michael Elizabeth Chastain: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33916
void dirty_stack()
{
unsigned char array_on_stack[4096];
for (unsigned i = 0; i < sizeof(array_on_stack); ++i)
{
array_on_stack[i] = 0x11;
}
}
}
int main()
{
dirty_stack();
// TODO More types may be added later.
const unsigned num_failures =
FAILED_TO_VALUE_INITIALIZE(boost::value_initialized<derived_struct>()) +
FAILED_TO_VALUE_INITIALIZE(boost::value_initialized<virtual_destructor_holder[2]>()) +
FAILED_TO_VALUE_INITIALIZE(boost::value_initialized<private_int_array_pair>());
#ifdef BOOST_DETAIL_VALUE_INIT_WORKAROUND_SUGGESTED
// One or more failures are expected.
return num_failures > 0 ? EXIT_SUCCESS : EXIT_FAILURE;
#else
// No failures are expected.
return num_failures == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
#endif
}