Fix Visual Studio 2013 build

This commit is contained in:
Vinnie Falco
2014-04-15 07:37:04 -07:00
parent a4ef993282
commit c0dfbdc910
4 changed files with 84 additions and 51 deletions

View File

@@ -253,6 +253,7 @@
<ClInclude Include="..\..\beast\utility\PropertyStream.h" />
<ClInclude Include="..\..\beast\utility\StaticObject.h" />
<ClInclude Include="..\..\beast\utility\type_name.h" />
<ClInclude Include="..\..\beast\utility\zero.h" />
<ClInclude Include="..\..\beast\Version.h" />
<ClInclude Include="..\..\modules\beast_asio\async\AsyncObject.h" />
<ClInclude Include="..\..\modules\beast_asio\basics\FixedInputBuffer.h" />
@@ -767,7 +768,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\beast\utility\tests\hardened_hash.test.cpp">
<ClCompile Include="..\..\beast\utility\tests\Zero.test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>

View File

@@ -1201,6 +1201,9 @@
<ClInclude Include="..\..\beast\utility\type_name.h">
<Filter>beast\utility</Filter>
</ClInclude>
<ClInclude Include="..\..\beast\utility\zero.h">
<Filter>beast\utility</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\modules\beast_core\files\DirectoryIterator.cpp">
@@ -1647,9 +1650,6 @@
<ClCompile Include="..\..\beast\threads\tests\Atomic.test.cpp">
<Filter>beast\threads\tests</Filter>
</ClCompile>
<ClCompile Include="..\..\beast\utility\tests\hardened_hash.test.cpp">
<Filter>beast\utility\tests</Filter>
</ClCompile>
<ClCompile Include="..\..\beast\crypto\tests\BinaryEncoding.cpp">
<Filter>beast\crypto\tests</Filter>
</ClCompile>
@@ -1665,6 +1665,9 @@
<ClCompile Include="..\..\beast\container\impl\spookyv2.cpp">
<Filter>beast\container\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\beast\utility\tests\Zero.test.cpp">
<Filter>beast\utility\tests</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="..\..\TODO.txt">

View File

@@ -22,6 +22,9 @@
#include "../config/CompilerConfig.h"
// VS2013 SP1 fails with decltype return
#define BEAST_NO_ZERO_AUTO_RETURN 1
namespace beast {
/** Zero allows classes to offer efficient comparisons to zero.
@@ -39,102 +42,122 @@ namespace beast {
returns a positive number, 0, or a negative; or there needs to be a signum
function which resolves in the namespace which takes an instance of T and
returns a positive, zero or negative number.
*/
*/
struct Zero {};
struct Zero
{
};
namespace {
static BEAST_CONSTEXPR Zero zero{};
}
} // namespace
/** The default implementation of signum calls the method on the class.
Calls to signum must be made from a namespace that does not include
overloads of the function.
*/
/** Default implementation of signum calls the method on the class. */
template <typename T>
auto signum(T const& t) -> decltype(t.signum()) {
#if BEAST_NO_ZERO_AUTO_RETURN
int signum(T const& t)
#else
auto signum(T const& t) -> decltype(t.signum())
#endif
{
return t.signum();
}
namespace detail {
namespace zero_helper {
// For argument dependent lookup to function properly, calls to signum must
// be made from a namespace that does not include overloads of the function..
template <class T>
auto call_signum (T const& t) -> decltype(signum(t)) {
#if BEAST_NO_ZERO_AUTO_RETURN
int call_signum (T const& t)
#else
auto call_signum(T const& t) -> decltype(t.signum())
#endif
{
return signum(t);
}
} // zero_helper
} // detail
/** Handle operators where T is on the left side using signum. */
// Handle operators where T is on the left side using signum.
template <typename T>
bool operator==(T const& t, Zero) {
bool operator==(T const& t, Zero)
{
return detail::zero_helper::call_signum(t) == 0;
}
template <typename T>
bool operator!=(T const& t, Zero) {
bool operator!=(T const& t, Zero)
{
return detail::zero_helper::call_signum(t) != 0;
}
template <typename T>
bool operator>(T const& t, Zero) {
return detail::zero_helper::call_signum(t) > 0;
}
template <typename T>
bool operator>=(T const& t, Zero) {
return detail::zero_helper::call_signum(t) >= 0;
}
template <typename T>
bool operator<(T const& t, Zero) {
bool operator<(T const& t, Zero)
{
return detail::zero_helper::call_signum(t) < 0;
}
template <typename T>
bool operator<=(T const& t, Zero) {
bool operator>(T const& t, Zero)
{
return detail::zero_helper::call_signum(t) > 0;
}
template <typename T>
bool operator>=(T const& t, Zero)
{
return detail::zero_helper::call_signum(t) >= 0;
}
template <typename T>
bool operator<=(T const& t, Zero)
{
return detail::zero_helper::call_signum(t) <= 0;
}
// Handle operators where T is on the right side by
// reversing the operation, so that T is on the left side.
/** Handle operators where T is on the right side by reversing the operation,
so that T is on the left side.
*/
template <typename T>
bool operator==(Zero, T const& t) {
bool operator==(Zero, T const& t)
{
return t == zero;
}
template <typename T>
bool operator!=(Zero, T const& t) {
bool operator!=(Zero, T const& t)
{
return t != zero;
}
template <typename T>
bool operator>(Zero, T const& t) {
return t < zero;
}
template <typename T>
bool operator>=(Zero, T const& t) {
return t <= zero;
}
template <typename T>
bool operator<(Zero, T const& t) {
bool operator<(Zero, T const& t)
{
return t > zero;
}
template <typename T>
bool operator<=(Zero, T const& t) {
bool operator>(Zero, T const& t)
{
return t < zero;
}
template <typename T>
bool operator>=(Zero, T const& t)
{
return t <= zero;
}
template <typename T>
bool operator<=(Zero, T const& t)
{
return t >= zero;
}
} // beast
} // beast
#endif

View File

@@ -25,14 +25,20 @@ namespace beast {
struct adl_tester {};
int signum (adl_tester) { return 0; }
int signum (adl_tester)
{
return 0;
}
namespace detail {
struct adl_tester2 {};
int signum (adl_tester2) { return 0; }
int signum (adl_tester2)
{
return 0;
}
} // detail