-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from pfultz2/msvc-alias
Msvc alias
- Loading branch information
Showing
30 changed files
with
671 additions
and
386 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
|
||
os: Visual Studio 2015 RC | ||
os: Visual Studio 2015 | ||
|
||
environment: | ||
matrix: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/*============================================================================= | ||
Copyright (c) 2015 Paul Fultz II | ||
alias.h | ||
Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
==============================================================================*/ | ||
|
||
#ifndef FIT_GUARD_ALIAS_H | ||
#define FIT_GUARD_ALIAS_H | ||
|
||
#include <fit/returns.h> | ||
#include <fit/detail/delegate.h> | ||
#include <fit/detail/move.h> | ||
#include <fit/detail/holder.h> | ||
|
||
/// alias | ||
/// ===== | ||
/// | ||
/// Description | ||
/// ----------- | ||
/// | ||
/// The `alias` class wraps a type with a new type that can be tagged by the | ||
/// user. | ||
/// | ||
/// Synopsis | ||
/// -------- | ||
/// | ||
/// // Alias the type using a member variable | ||
/// template<class T, class Tag=void> | ||
/// class alias; | ||
/// | ||
/// // Alias the type by inheriting | ||
/// template<class T, class Tag=void> | ||
/// class alias_inherit; | ||
/// | ||
/// // Alias the type using a static variable | ||
/// template<class T, class Tag=void> | ||
/// class alias_static; | ||
/// | ||
/// // Retrieve tag from alias | ||
/// template<class Alias> | ||
/// class alias_tag; | ||
/// | ||
/// // Check if type has a certian tag | ||
/// template<class T, class Tag> | ||
/// class has_tag; | ||
/// | ||
/// // Retrieve value from alias | ||
/// template<class Alias> | ||
/// constexpr auto alias_value(Alias&&); | ||
/// | ||
|
||
namespace fit { | ||
|
||
template<class T> | ||
struct alias_tag; | ||
|
||
template<class T, class Tag, class=void> | ||
struct has_tag | ||
: std::false_type | ||
{}; | ||
|
||
template<class T, class Tag> | ||
struct has_tag<T, Tag, typename detail::holder< | ||
typename alias_tag<T>::type | ||
>::type> | ||
: std::is_same<typename alias_tag<T>::type, Tag> | ||
{}; | ||
|
||
namespace detail { | ||
|
||
template<class T> | ||
constexpr T& lvalue(T& x) | ||
{ | ||
return x; | ||
} | ||
|
||
template<class T> | ||
constexpr const T& lvalue(const T& x) | ||
{ | ||
return x; | ||
} | ||
|
||
} | ||
|
||
#define FIT_UNARY_PERFECT_ID(...) __VA_ARGS__ | ||
#define FIT_UNARY_PERFECT_FOREACH(m) \ | ||
m(const&, fit::detail::lvalue) \ | ||
m(&, fit::detail::lvalue) \ | ||
m(&&, fit::move) \ | ||
|
||
template<class T, class Tag=void> | ||
struct alias | ||
{ | ||
T value; | ||
FIT_DELGATE_CONSTRUCTOR(alias, T, value) | ||
}; | ||
|
||
#define FIT_DETAIL_ALIAS_GET_VALUE(ref, move) \ | ||
template<class T, class Tag, class... Ts> \ | ||
constexpr auto alias_value(alias<T, Tag> ref a, Ts&&...) FIT_RETURNS(move(a.value)) | ||
FIT_UNARY_PERFECT_FOREACH(FIT_DETAIL_ALIAS_GET_VALUE) | ||
|
||
template<class T, class Tag> | ||
struct alias_tag<alias<T, Tag>> | ||
{ typedef Tag type; }; | ||
|
||
|
||
template<class T, class Tag=void> | ||
struct alias_inherit | ||
#if (defined(__GNUC__) && !defined (__clang__)) | ||
: std::conditional<(std::is_class<T>::value), T, alias<T>>::type | ||
#else | ||
: T | ||
#endif | ||
{ | ||
FIT_INHERIT_CONSTRUCTOR(alias_inherit, T) | ||
}; | ||
|
||
#define FIT_DETAIL_ALIAS_INHERIT_GET_VALUE(ref, move) \ | ||
template<class T, class Tag, class... Ts, class=typename std::enable_if<(std::is_class<T>::value)>::type> \ | ||
constexpr T ref alias_value(alias_inherit<T, Tag> ref a, Ts&&...) \ | ||
{ \ | ||
return move(a); \ | ||
} | ||
FIT_UNARY_PERFECT_FOREACH(FIT_DETAIL_ALIAS_INHERIT_GET_VALUE) | ||
|
||
template<class T, class Tag> | ||
struct alias_tag<alias_inherit<T, Tag>> | ||
{ typedef Tag type; }; | ||
|
||
namespace detail { | ||
|
||
template<class T, class Tag> | ||
struct alias_static_storage | ||
{ | ||
static constexpr T value = T(); | ||
}; | ||
|
||
template<class T, class Tag> | ||
constexpr T alias_static_storage<T, Tag>::value; | ||
|
||
} | ||
|
||
template<class T, class Tag=void> | ||
struct alias_static | ||
{ | ||
template<class... Ts, FIT_ENABLE_IF_CONSTRUCTIBLE(T, Ts...)> | ||
constexpr alias_static(Ts&&...) | ||
{} | ||
}; | ||
|
||
template<class T, class Tag, class... Ts> | ||
constexpr const T& alias_value(const alias_static<T, Tag>&, Ts&&...) | ||
{ | ||
return detail::alias_static_storage<T, Tag>::value; | ||
} | ||
|
||
template<class T, class Tag> | ||
struct alias_tag<alias_static<T, Tag>> | ||
{ typedef Tag type; }; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.