make_default.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /// @file
  2. // Copyright (c) 2009-2016 Vladimir Batov.
  3. // Use, modification and distribution are subject to the Boost Software License,
  4. // Version 1.0. See http://www.boost.org/LICENSE_1_0.txt.
  5. #ifndef BOOST_MAKE_DEFAULT_HPP
  6. #define BOOST_MAKE_DEFAULT_HPP
  7. namespace boost
  8. {
  9. /// @details A considerable number of libraries require an instance of a class
  10. /// provided (storage created and initialized). For example,
  11. /// @code
  12. /// Type result;
  13. /// ...
  14. /// istream >> result;
  15. /// @endcode
  16. /// In generic code that results in the Default Constructibility requirement imposed
  17. /// on every type 'Type' to be used with the respective code. Inevitably, that requirement
  18. /// a) either excludes all the classes that for various reasons do not meet that requirement or
  19. /// b) imposes certain (not necessarily desirable) design/implementation onto respective classes.
  20. ///
  21. /// Deployment of boost::make_default() eliminates the Default Constructibility requirement with
  22. /// @code
  23. /// Type result = boost::make_default<Type>();
  24. /// ...
  25. /// istream >> result;
  26. /// @endcode
  27. /// Classes with no default constructor can now be included via a boost::make_default() specialization:
  28. /// @code
  29. /// namespace boost
  30. /// {
  31. /// template<> inline Type make_default<Type>() { return Type(parameters); }
  32. /// }
  33. /// @endcode
  34. template<typename T> T make_default() { return T(); }
  35. }
  36. #endif // BOOST_MAKE_DEFAULT_HPP