add functional polymorphic specializations

This commit is contained in:
bolero-MURAKAMI 2012-10-25 12:50:03 +09:00
parent 5cb070b3b3
commit c8e2514d36
21 changed files with 300 additions and 19 deletions

View file

@ -1,11 +1,13 @@
#ifndef SPROUT_FUNCTIONAL_BIT_AND_HPP
#define SPROUT_FUNCTIONAL_BIT_AND_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// 20.8.7 bitwise operations
template<typename T>
template<typename T = void>
struct bit_and {
public:
typedef T first_argument_type;
@ -16,6 +18,18 @@ namespace sprout {
return x & y;
}
};
template<>
struct bit_and<void> {
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>() & std::declval<U>())
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<T>() & std::declval<U>()))
{
return sprout::forward<T>(x) & sprout::forward<U>(y);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_BIT_AND_HPP

View file

@ -1,11 +1,13 @@
#ifndef SPROUT_FUNCTIONAL_BIT_NOT_HPP
#define SPROUT_FUNCTIONAL_BIT_NOT_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// 20.8.7 bitwise operations
template<typename T>
template<typename T = void>
struct bit_not {
public:
typedef T argument_type;
@ -15,6 +17,18 @@ namespace sprout {
return ~x;
}
};
template<>
struct bit_not<void> {
public:
template<typename T>
SPROUT_CONSTEXPR decltype(~std::declval<T>())
operator()(T&& x)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(~std::declval<T>()))
{
return ~sprout::forward<T>(x);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_BIT_NOT_HPP

View file

@ -1,11 +1,13 @@
#ifndef SPROUT_FUNCTIONAL_BIT_OR_HPP
#define SPROUT_FUNCTIONAL_BIT_OR_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// 20.8.7 bitwise operations
template<typename T>
template<typename T = void>
struct bit_or {
public:
typedef T first_argument_type;
@ -16,6 +18,18 @@ namespace sprout {
return x | y;
}
};
template<>
struct bit_or<void> {
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>() | std::declval<U>())
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<T>() | std::declval<U>()))
{
return sprout::forward<T>(x) | sprout::forward<U>(y);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_BIT_OR_HPP

View file

@ -1,11 +1,13 @@
#ifndef SPROUT_FUNCTIONAL_BIT_XOR_HPP
#define SPROUT_FUNCTIONAL_BIT_XOR_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// 20.8.7 bitwise operations
template<typename T>
template<typename T = void>
struct bit_xor {
public:
typedef T first_argument_type;
@ -16,6 +18,18 @@ namespace sprout {
return x ^ y;
}
};
template<>
struct bit_xor<void> {
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>() ^ std::declval<U>())
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<T>() ^ std::declval<U>()))
{
return sprout::forward<T>(x) ^ sprout::forward<U>(y);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_BIT_XOR_HPP

View file

@ -1,13 +1,15 @@
#ifndef SPROUT_FUNCTIONAL_DEVIDES_HPP
#define SPROUT_FUNCTIONAL_DEVIDES_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 20.8.4 Arithmetic operations
template<typename T>
template<typename T = void>
struct divides {
public:
typedef T first_argument_type;
@ -18,6 +20,18 @@ namespace sprout {
return x / y;
}
};
template<>
struct divides<void> {
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>() / std::declval<U>())
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<T>() / std::declval<U>()))
{
return sprout::forward<T>(x) / sprout::forward<U>(y);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_DEVIDES_HPP

View file

@ -1,13 +1,15 @@
#ifndef SPROUT_FUNCTIONAL_EQUAL_TO_HPP
#define SPROUT_FUNCTIONAL_EQUAL_TO_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 20.8.5 Comparisons
template<typename T>
template<typename T = void>
struct equal_to {
public:
typedef T first_argument_type;
@ -18,6 +20,18 @@ namespace sprout {
return x == y;
}
};
template<>
struct equal_to<void> {
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>() == std::declval<U>())
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<T>() == std::declval<U>()))
{
return sprout::forward<T>(x) == sprout::forward<U>(y);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_EQUAL_TO_HPP

View file

@ -1,13 +1,15 @@
#ifndef SPROUT_FUNCTIONAL_GREATER_HPP
#define SPROUT_FUNCTIONAL_GREATER_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 20.8.5 Comparisons
template<typename T>
template<typename T = void>
struct greater {
public:
typedef T first_argument_type;
@ -18,6 +20,18 @@ namespace sprout {
return x > y;
}
};
template<>
struct greater<void> {
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>() > std::declval<U>())
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<T>() > std::declval<U>()))
{
return sprout::forward<T>(x) > sprout::forward<U>(y);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_GREATER_HPP

View file

@ -1,13 +1,15 @@
#ifndef SPROUT_FUNCTIONAL_GREATER_EQUAL_HPP
#define SPROUT_FUNCTIONAL_GREATER_EQUAL_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 20.8.5 Comparisons
template<typename T>
template<typename T = void>
struct greater_equal {
public:
typedef T first_argument_type;
@ -18,6 +20,18 @@ namespace sprout {
return x >= y;
}
};
template<>
struct greater_equal<void> {
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>() >= std::declval<U>())
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<T>() >= std::declval<U>()))
{
return sprout::forward<T>(x) >= sprout::forward<U>(y);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_GREATER_EQUAL_HPP

View file

@ -1,13 +1,15 @@
#ifndef SPROUT_FUNCTIONAL_LESS_HPP
#define SPROUT_FUNCTIONAL_LESS_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 20.8.5 Comparisons
template<typename T>
template<typename T = void>
struct less {
public:
typedef T first_argument_type;
@ -18,6 +20,18 @@ namespace sprout {
return x < y;
}
};
template<>
struct less<void> {
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>() < std::declval<U>())
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<T>() < std::declval<U>()))
{
return sprout::forward<T>(x) < sprout::forward<U>(y);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_LESS_HPP

View file

@ -1,7 +1,9 @@
#ifndef SPROUT_FUNCTIONAL_LESS_EQUAL_HPP
#define SPROUT_FUNCTIONAL_LESS_EQUAL_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
@ -18,6 +20,18 @@ namespace sprout {
return x <= y;
}
};
template<>
struct less_equal<void> {
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>() <= std::declval<U>())
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<T>() <= std::declval<U>()))
{
return sprout::forward<T>(x) <= sprout::forward<U>(y);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_LESS_EQUAL_HPP

View file

@ -1,11 +1,13 @@
#ifndef SPROUT_FUNCTIONAL_LOGICAL_AND_HPP
#define SPROUT_FUNCTIONAL_LOGICAL_AND_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// 20.8.6 logical operations
template<typename T>
template<typename T = void>
struct logical_and {
public:
typedef T first_argument_type;
@ -16,6 +18,18 @@ namespace sprout {
return x && y;
}
};
template<>
struct logical_and<void> {
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>() && std::declval<U>())
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<T>() && std::declval<U>()))
{
return sprout::forward<T>(x) && sprout::forward<U>(y);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_LOGICAL_AND_HPP

View file

@ -1,11 +1,13 @@
#ifndef SPROUT_FUNCTIONAL_LOGICAL_NOT_HPP
#define SPROUT_FUNCTIONAL_LOGICAL_NOT_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// 20.8.6 logical operations
template<typename T>
template<typename T = void>
struct logical_not {
public:
typedef T argument_type;
@ -15,6 +17,18 @@ namespace sprout {
return !x;
}
};
template<>
struct logical_not<void> {
public:
template<typename T>
SPROUT_CONSTEXPR decltype(!std::declval<T>())
operator()(T&& x)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(!std::declval<T>()))
{
return !sprout::forward<T>(x);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_LOGICAL_NOT_HPP

View file

@ -1,11 +1,13 @@
#ifndef SPROUT_FUNCTIONAL_LOGICAL_OR_HPP
#define SPROUT_FUNCTIONAL_LOGICAL_OR_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// 20.8.6 logical operations
template<typename T>
template<typename T = void>
struct logical_or {
public:
typedef T first_argument_type;
@ -16,6 +18,18 @@ namespace sprout {
return x || y;
}
};
template<>
struct logical_or<void> {
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>() || std::declval<U>())
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<T>() || std::declval<U>()))
{
return sprout::forward<T>(x) || sprout::forward<U>(y);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_LOGICAL_OR_HPP

View file

@ -1,13 +1,15 @@
#ifndef SPROUT_FUNCTIONAL_MINUS_HPP
#define SPROUT_FUNCTIONAL_MINUS_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 20.8.4 Arithmetic operations
template<typename T>
template<typename T = void>
struct minus {
public:
typedef T first_argument_type;
@ -18,6 +20,18 @@ namespace sprout {
return x - y;
}
};
template<>
struct minus<void> {
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>() - std::declval<U>())
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<T>() - std::declval<U>()))
{
return sprout::forward<T>(x) - sprout::forward<U>(y);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_MINUS_HPP

View file

@ -1,13 +1,15 @@
#ifndef SPROUT_FUNCTIONAL_MODULUS_HPP
#define SPROUT_FUNCTIONAL_X_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 20.8.4 Arithmetic operations
template<typename T>
template<typename T = void>
struct modulus {
public:
typedef T first_argument_type;
@ -18,6 +20,18 @@ namespace sprout {
return x % y;
}
};
template<>
struct modulus<void> {
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>() % std::declval<U>())
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<T>() % std::declval<U>()))
{
return sprout::forward<T>(x) % sprout::forward<U>(y);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_MODULUS_HPP

View file

@ -1,13 +1,15 @@
#ifndef SPROUT_FUNCTIONAL_MULTIPLIES_HPP
#define SPROUT_FUNCTIONAL_MULTIPLIES_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 20.8.4 Arithmetic operations
template<typename T>
template<typename T = void>
struct multiplies {
public:
typedef T first_argument_type;
@ -18,6 +20,18 @@ namespace sprout {
return x * y;
}
};
template<>
struct multiplies<void> {
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>() * std::declval<U>())
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<T>() * std::declval<U>()))
{
return sprout::forward<T>(x) * sprout::forward<U>(y);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_MULTIPLIES_HPP

View file

@ -1,13 +1,15 @@
#ifndef SPROUT_FUNCTIONAL_NEGATE_HPP
#define SPROUT_FUNCTIONAL_NEGATE_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 20.8.4 Arithmetic operations
template<typename T>
template<typename T = void>
struct negate {
public:
typedef T argument_type;
@ -17,6 +19,18 @@ namespace sprout {
return -x;
}
};
template<>
struct negate<void> {
public:
template<typename T>
SPROUT_CONSTEXPR decltype(-std::declval<T>())
operator()(T&& x)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(-std::declval<T>()))
{
return -sprout::forward<T>(x);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_NEGATE_HPP

View file

@ -1,13 +1,15 @@
#ifndef SPROUT_FUNCTIONAL_NOT_EQUAL_TO_HPP
#define SPROUT_FUNCTIONAL_NOT_EQUAL_TO_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 20.8.5 Comparisons
template<typename T>
template<typename T = void>
struct not_equal_to {
public:
typedef T first_argument_type;
@ -18,6 +20,18 @@ namespace sprout {
return x != y;
}
};
template<>
struct not_equal_to<void> {
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>() != std::declval<U>())
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<T>() != std::declval<U>()))
{
return sprout::forward<T>(x) != sprout::forward<U>(y);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_NOT_EQUAL_TO_HPP

View file

@ -1,13 +1,15 @@
#ifndef SPROUT_FUNCTIONAL_PLUS_HPP
#define SPROUT_FUNCTIONAL_PLUS_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 20.8.4 Arithmetic operations
template<typename T>
template<typename T = void>
struct plus {
public:
typedef T first_argument_type;
@ -18,6 +20,18 @@ namespace sprout {
return x + y;
}
};
template<>
struct plus<void> {
public:
template<typename T, typename U>
SPROUT_CONSTEXPR decltype(std::declval<T>() + std::declval<U>())
operator()(T&& x, U&& y)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<T>() + std::declval<U>()))
{
return sprout::forward<T>(x) + sprout::forward<U>(y);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_PLUS_HPP

View file

@ -7,6 +7,7 @@
#include <sprout/functional/polymorphic/logical.hpp>
#include <sprout/functional/polymorphic/bitwise.hpp>
#include <sprout/functional/polymorphic/inc_dec.hpp>
#include <sprout/functional/polymorphic/reference.hpp>
#include <sprout/functional/polymorphic/assignment.hpp>
#include <sprout/functional/polymorphic/members.hpp>
#include <sprout/functional/polymorphic/various.hpp>

View file

@ -1,13 +1,15 @@
#ifndef SPROUT_FUNCTIONAL_POSITE_HPP
#define SPROUT_FUNCTIONAL_POSITE_HPP
#include <utility>
#include <sprout/config.hpp>
#include <sprout/utility/forward.hpp>
namespace sprout {
// Copyright (C) 2011 RiSK (sscrisk)
// 20.8.4 Arithmetic operations
template<typename T>
template<typename T = void>
struct posite {
public:
typedef T argument_type;
@ -17,6 +19,18 @@ namespace sprout {
return +x;
}
};
template<>
struct posite<void> {
public:
template<typename T>
SPROUT_CONSTEXPR decltype(+std::declval<T>())
operator()(T&& x)
const SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(+std::declval<T>()))
{
return +sprout::forward<T>(x);
}
};
} // namespace sprout
#endif // #ifndef SPROUT_FUNCTIONAL_POSITE_HPP