fork download
  1. #include <algorithm>
  2. #include <cmath>
  3. #include <iostream>
  4. #include <iterator>
  5. #include <type_traits>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. template <typename T>
  11. enable_if_t<decltype(div(declval<T>(), declval<T>())){ 1, 0 }.quot != 0, decltype(div(declval<T>(), declval<T>()))> make_div(const T quot, const T rem) { return { quot, rem }; }
  12. template <typename T>
  13. enable_if_t<decltype(div(declval<T>(), declval<T>())){ 1, 0 }.quot == 0, decltype(div(declval<T>(), declval<T>()))> make_div(const T quot, const T rem) { return { rem, quot }; }
  14.  
  15. int main() {
  16. const auto test = make_div(1, 2);
  17.  
  18. cout << test.quot << ' ' << test.rem << endl;
  19. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
1 2