Skip to content

Instantly share code, notes, and snippets.

@johnbartholomew
Created December 16, 2012 23:09
Show Gist options
  • Save johnbartholomew/4314023 to your computer and use it in GitHub Desktop.
Save johnbartholomew/4314023 to your computer and use it in GitHub Desktop.
Checking overloads for sin and cos functions in C++11
#include <cmath>
#include <type_traits>
static_assert(std::is_same<float, decltype(std::sin(3.1f))>::value,
"std::sin not overloaded for float");
static_assert(std::is_same<double, decltype(std::sin(3.1))>::value,
"std::sin not overloaded for double");
static_assert(std::is_same<long double, decltype(std::sin(3.1l))>::value,
"std::sin not overloaded for long double");
static_assert(std::is_same<float, decltype(::sin(3.1f))>::value,
"::sin not overloaded for float");
static_assert(std::is_same<double, decltype(::sin(3.1))>::value,
"::sin not overloaded for double");
static_assert(std::is_same<long double, decltype(::sin(3.1l))>::value,
"::sin not overloaded for long double");
// With gcc version 4.7.2, compiling with g++ -std=c++11 -c test.cpp, I get:
//
// test.cpp:11:1: error: static assertion failed: ::sin not overloaded for float
// test.cpp:15:1: error: static assertion failed: ::sin not overloaded for long double
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment