constant_side_effects.cpp 744 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright Louis Dionne 2013-2017
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  4. #include <boost/hana/bool.hpp>
  5. #include <iostream>
  6. namespace hana = boost::hana;
  7. namespace pure {
  8. //! [pure]
  9. template <typename X>
  10. auto identity(X x) { return x; }
  11. auto x = identity(hana::bool_c<true>);
  12. static_assert(hana::value(x), "");
  13. //! [pure]
  14. }
  15. namespace impure {
  16. //! [impure_identity]
  17. template <typename X>
  18. auto identity(X x) {
  19. std::cout << "Good luck in evaluating this at compile-time!";
  20. return x;
  21. }
  22. //! [impure_identity]
  23. //! [impure]
  24. auto x = identity(hana::bool_c<true>);
  25. static_assert(hana::value(x), "");
  26. //! [impure]
  27. }
  28. int main() { }