Implement n3789; constexpr support in named function objects

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@191626 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow
2013-09-28 19:06:12 +00:00
parent 6db12cb037
commit 9738cafa4f
21 changed files with 201 additions and 45 deletions

View File

@@ -27,5 +27,11 @@ int main()
assert(f2(36, 4) == 9);
assert(f2(36.0, 4) == 9);
assert(f2(18, 4.0) == 4.5); // exact in binary
constexpr int foo = std::divides<int> () (3, 2);
static_assert ( foo == 1, "" );
constexpr int bar = std::divides<> () (3.0, 2);
static_assert ( bar == 1, "" );
#endif
}

View File

@@ -27,5 +27,11 @@ int main()
assert(f2(3,2) == 1);
assert(f2(3.0, 2) == 1);
assert(f2(3, 2.5) == 0.5);
constexpr int foo = std::minus<int> () (3, 2);
static_assert ( foo == 1, "" );
constexpr int bar = std::minus<> () (3.0, 2);
static_assert ( bar == 1, "" );
#endif
}

View File

@@ -27,5 +27,11 @@ int main()
assert(f2(36, 8) == 4);
assert(f2(36L, 8) == 4);
assert(f2(36, 8L) == 4);
constexpr int foo = std::modulus<int> () (3, 2);
static_assert ( foo == 1, "" );
constexpr int bar = std::modulus<> () (3L, 2);
static_assert ( bar == 1, "" );
#endif
}

View File

@@ -27,5 +27,11 @@ int main()
assert(f2(3,2) == 6);
assert(f2(3.0, 2) == 6);
assert(f2(3, 2.5) == 7.5); // exact in binary
constexpr int foo = std::multiplies<int> () (3, 2);
static_assert ( foo == 6, "" );
constexpr int bar = std::multiplies<> () (3.0, 2);
static_assert ( bar == 6, "" );
#endif
}

View File

@@ -27,5 +27,11 @@ int main()
assert(f2(36) == -36);
assert(f2(36L) == -36);
assert(f2(36.0) == -36);
constexpr int foo = std::negate<int> () (3);
static_assert ( foo == -3, "" );
constexpr int bar = std::negate<> () (3.0);
static_assert ( bar == -3, "" );
#endif
}

View File

@@ -27,5 +27,11 @@ int main()
assert(f2(3,2) == 5);
assert(f2(3.0, 2) == 5);
assert(f2(3, 2.5) == 5.5);
constexpr int foo = std::plus<int> () (3, 2);
static_assert ( foo == 5, "" );
constexpr int bar = std::plus<> () (3.0, 2);
static_assert ( bar == 5, "" );
#endif
}

View File

@@ -47,5 +47,11 @@ int main()
assert(f2(0xFFFF, 0x58D3) == 0x58D3);
assert(f2(0xFFFFL, 0x58D3) == 0x58D3);
assert(f2(0xFFFF, 0x58D3L) == 0x58D3);
constexpr int foo = std::bit_and<int> () (0x58D3, 0xEA95);
static_assert ( foo == 0x4891, "" );
constexpr int bar = std::bit_and<> () (0x58D3L, 0xEA95);
static_assert ( bar == 0x4891, "" );
#endif
}

View File

@@ -36,5 +36,11 @@ int main()
assert((f2(0L) & 0xFFFF ) == 0xFFFF);
assert((f2(0xFFFF) & 0xFFFF ) == 0);
assert((f2(0xFFFFL) & 0xFFFF ) == 0);
constexpr int foo = std::bit_not<int> () (0xEA95) & 0xFFFF;
static_assert ( foo == 0x156A, "" );
constexpr int bar = std::bit_not<> () (0xEA95) & 0xFFFF;
static_assert ( bar == 0x156A, "" );
#endif
}

View File

@@ -47,5 +47,11 @@ int main()
assert(f2(0xFFFF, 0x58D3) == 0xFFFF);
assert(f2(0xFFFFL, 0x58D3) == 0xFFFF);
assert(f2(0xFFFF, 0x58D3L) == 0xFFFF);
constexpr int foo = std::bit_or<int> () (0x58D3, 0xEA95);
static_assert ( foo == 0xFAD7, "" );
constexpr int bar = std::bit_or<> () (0x58D3L, 0xEA95);
static_assert ( bar == 0xFAD7, "" );
#endif
}

View File

@@ -47,5 +47,11 @@ int main()
assert(f(0xFFFF, 0x58D3) == 0xA72C);
assert(f(0xFFFFL, 0x58D3) == 0xA72C);
assert(f(0xFFFF, 0x58D3L) == 0xA72C);
constexpr int foo = std::bit_xor<int> () (0x58D3, 0xEA95);
static_assert ( foo == 0xB246, "" );
constexpr int bar = std::bit_xor<> () (0x58D3L, 0xEA95);
static_assert ( bar == 0xB246, "" );
#endif
}

View File

@@ -29,5 +29,11 @@ int main()
assert(!f2(36, 6));
assert(f2(36, 36.0));
assert(f2(36.0, 36L));
constexpr bool foo = std::equal_to<int> () (36, 36);
static_assert ( foo, "" );
constexpr bool bar = std::equal_to<> () (36.0, 36);
static_assert ( bar, "" );
#endif
}

View File

@@ -33,5 +33,11 @@ int main()
assert( f2(36.0, 6));
assert(!f2(6, 36.0));
assert(!f2(6.0, 36));
constexpr bool foo = std::greater<int> () (36, 36);
static_assert ( !foo, "" );
constexpr bool bar = std::greater<> () (36.0, 36);
static_assert ( !bar, "" );
#endif
}

View File

@@ -33,5 +33,11 @@ int main()
assert( f2(36.0, 6));
assert(!f2(6, 36.0));
assert(!f2(6.0, 36));
constexpr bool foo = std::greater_equal<int> () (36, 36);
static_assert ( foo, "" );
constexpr bool bar = std::greater_equal<> () (36.0, 36);
static_assert ( bar, "" );
#endif
}

View File

@@ -33,5 +33,11 @@ int main()
assert(!f2(36.0, 6));
assert( f2(6, 36.0));
assert( f2(6.0, 36));
constexpr bool foo = std::less<int> () (36, 36);
static_assert ( !foo, "" );
constexpr bool bar = std::less<> () (36.0, 36);
static_assert ( !bar, "" );
#endif
}

View File

@@ -33,5 +33,11 @@ int main()
assert(!f2(36.0, 6));
assert( f2(6, 36.0));
assert( f2(6.0, 36));
constexpr bool foo = std::less_equal<int> () (36, 36);
static_assert ( foo, "" );
constexpr bool bar = std::less_equal<> () (36.0, 36);
static_assert ( bar, "" );
#endif
}

View File

@@ -31,5 +31,11 @@ int main()
assert( f2(36.0, 6));
assert(!f2(36.0, 36));
assert(!f2(36, 36.0));
constexpr bool foo = std::not_equal_to<int> () (36, 36);
static_assert ( !foo, "" );
constexpr bool bar = std::not_equal_to<> () (36.0, 36);
static_assert ( !bar, "" );
#endif
}

View File

@@ -38,5 +38,11 @@ int main()
assert( f2(36L, 36));
assert(!f2(36L, 0));
assert(!f2(0L, 36));
constexpr bool foo = std::logical_and<int> () (36, 36);
static_assert ( foo, "" );
constexpr bool bar = std::logical_and<> () (36.0, 36);
static_assert ( bar, "" );
#endif
}

View File

@@ -29,5 +29,11 @@ int main()
assert( f2(0));
assert(!f2(36L));
assert( f2(0L));
constexpr bool foo = std::logical_not<int> () (36);
static_assert ( !foo, "" );
constexpr bool bar = std::logical_not<> () (36);
static_assert ( !bar, "" );
#endif
}

View File

@@ -37,5 +37,11 @@ int main()
assert(!f2(0, 0));
assert(!f2(0, 0L));
assert(!f2(0L, 0));
constexpr bool foo = std::logical_or<int> () (36, 36);
static_assert ( foo, "" );
constexpr bool bar = std::logical_or<> () (36.0, 36);
static_assert ( bar, "" );
#endif
}