complex_helpers.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * cxxomfort example: complex helpers
  3. *
  4. */
  5. #include <cxxomfort/base.hpp>
  6. #include <cxxomfort/complex.hpp>
  7. //#include <cxxomfort/library/complex.hpp>
  8. #include <cxxomfort/ostream.hpp>
  9. #include <cxxomfort/library/type_name.hpp>
  10. #include <iostream>
  11. using cxxomfort::type_name;
  12. void test_std_literals ();
  13. void test_user_literals ();
  14. int main () {
  15. using namespace std;
  16. cxxomfort::output_info(stdout); cout<< endl;
  17. cout<< "Feature macro: "<< CXXO_IF_MACRO(__cpp_lib_complex_udls,'_')<< endl;
  18. cout<< "\n\n";
  19. cout<< "_i literal built-in:"<< endl;
  20. {
  21. using namespace cxxomfort::fix::complex_helpers;
  22. cout<< type_name< CXXO_TYPEOF(3.1-i_c(2.2)) >()<< endl;
  23. cout<< type_name< CXXO_TYPEOF(3.1f-if_c(2.2)) >()<< endl;
  24. cout<< type_name< CXXO_TYPEOF(3.1L-il_c(2.2)) >()<< endl;
  25. }
  26. cout<< "\n----\n"<< endl;
  27. test_std_literals();
  28. test_user_literals();
  29. }
  30. void test_std_literals () {
  31. using namespace std;
  32. cout<< "std user-defined literals (\" \"i):"<< endl;
  33. #if (!defined(__cpp_lib_complex_udls))
  34. cout<< "unsupported in this compilation mode"<< endl;
  35. #else
  36. using namespace std::literals::complex_literals;
  37. cout<< type_name< CXXO_TYPEOF(3.1-2.2i) >()<< endl;
  38. cout<< type_name< CXXO_TYPEOF(3.1f-2.2if) >()<< endl;
  39. cout<< type_name< CXXO_TYPEOF(3.1L-2.2il) >()<< endl;
  40. #endif
  41. }
  42. void test_user_literals () {
  43. #if (CXXO_COMPILER_SUPPORT_user_defined_literals > 0)
  44. using namespace std;
  45. using namespace cxxomfort::fix::complex_literals;
  46. cout<< "cxxomfort::fix user-defined literals (\" \"_i):"<< endl;
  47. cout<< type_name< CXXO_TYPEOF(3.1-2.2_i) >()<< endl;
  48. cout<< type_name< CXXO_TYPEOF(3.1f-2.2_if) >()<< endl;
  49. cout<< type_name< CXXO_TYPEOF(3.1L-2.2_il) >()<< endl;
  50. #else
  51. std::cout<< "Not supported"<< std::endl;
  52. #endif
  53. }