From f1929a568f502fc144112a50318b413a03b1cc8a Mon Sep 17 00:00:00 2001
From: Christian Godenschwager <christian.godenschwager@fau.de>
Date: Tue, 27 Oct 2020 19:40:25 +0100
Subject: [PATCH] add user defined literal _r for real_t

---
 src/core/DataTypes.h         | 2 ++
 tests/core/DataTypesTest.cpp | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/src/core/DataTypes.h b/src/core/DataTypes.h
index 3ae37218d..28fdf80c7 100644
--- a/src/core/DataTypes.h
+++ b/src/core/DataTypes.h
@@ -163,6 +163,8 @@ typedef double real_t;
 typedef float  real_t;
 #endif
 
+inline real_t operator"" _r( long double t ) { return static_cast< real_t >(t); }
+inline real_t operator"" _r( unsigned long long int t ) { return static_cast< real_t >(t); }
 template< typename T > inline real_t real_c  ( T t ) { return numeric_cast< real_t >(t); } ///< cast to type real_t using "real_c(x)"
 template< typename T > inline double double_c( T t ) { return numeric_cast< double >(t); } ///< cast to type double
 template< typename T > inline float  float_c ( T t ) { return numeric_cast< float > (t); } ///< cast to type float
diff --git a/tests/core/DataTypesTest.cpp b/tests/core/DataTypesTest.cpp
index 4250c8d33..569a57f81 100644
--- a/tests/core/DataTypesTest.cpp
+++ b/tests/core/DataTypesTest.cpp
@@ -52,5 +52,9 @@ int main( int /*argc*/, char** /*argv*/ )
    WALBERLA_CHECK_EQUAL( math::int_ld<  2 >::exp, 1 );
    WALBERLA_CHECK_EQUAL( math::int_ld<  1 >::exp, 0 );
 
+   WALBERLA_CHECK_IDENTICAL(1.23456_r, real_c(1.23456));
+   WALBERLA_CHECK_IDENTICAL(1_r, real_c(1));
+   WALBERLA_CHECK_IDENTICAL(-1_r, real_c(-1));
+
    return EXIT_SUCCESS;
 }
-- 
GitLab