...

/

Solution: Implement Arithmetic Concept

Solution: Implement Arithmetic Concept

The solution to the challenge, "Implement Arithmetic Concept".

We'll cover the following...

Solution

Press + to interact
#include <type_traits>
#include <iostream>
#include <string>
template<typename T>
concept Arithmetic = std::is_arithmetic<T>::value;
template <Arithmetic T>
T sum(T a, T b) {
return a + b;
}
int main() {
std::cout << std::endl;
std::cout << "sum(2000, 11): " << sum(2000, 11) << std::endl;
// std::cout << "sum(2000, 10.5): " << sum(2000, 10.5 ) << std::endl;
std::string hello("Hello");
std::string world(" World");
// std::cout << "sum(hello, world): " << sum(hello, world) << std::endl;
std::cout << std::endl;
}
...