Marcel-Rodekamp / NSL

Nanosystem Simulation Library (NSL) implements statistical simulations for systems on the nanoscale
Other
2 stars 0 forks source link

Reverting Concepts #47

Open Marcel-Rodekamp opened 2 years ago

Marcel-Rodekamp commented 2 years ago

Clang currently does not support all C++20 concepts, e.g. std::floating_point. Therefore, the NSL::Concept members in #46 are using C++17 type_trait features, e.g. std::is_floating_point_v. Once Clang can compile the following code we should revert to using C++20 concepts (which are implemented similarly).

// file: test_concepts.cpp
// compilation linux: g++ -std=c++20 test_concepts.cpp && ./a.out
//         tested with: g++ (GCC) 11.2.0
// compilation macOs: clang --std=c++20 test_concepts.cpp && ./a.out
// compilation macOs: clang --std=gnu++2a test_concepts.cpp && ./a.out
//         tested with: Apple clang version 13.0.0

#include <iostream>
#include <type_traits>
#include <concepts>

template<std::floating_point Type>
void printer(Type x){
    std::cout << "Got " << x << " of type " << typeid(Type).name() << std::endl; 
}

int main(){

    printer(static_cast<float>(1.3));  // float
    printer(static_cast<double>(1.3)); // double
    //printer(static_cast<int>(1));      // compilation error 
}