Skip to content
Snippets Groups Projects
Commit 9ffc53b1 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

add ext::less implementation handling unrelated types

parent 312dd57b
No related branches found
No related tags found
No related merge requests found
......@@ -26,8 +26,36 @@
 
#include <functional>
 
#include "type_traits.hpp"
#include "typeindex.h"
namespace ext {
 
template < typename _Tp = void >
struct less;
template < typename _Tp >
struct less : public std::binary_function < _Tp, _Tp, bool > {
bool operator ( ) ( const _Tp & __x, const _Tp & __y ) const {
return __x < __y;
}
};
template < >
struct less < void > {
template < typename _Tp, typename _Up, typename std::enable_if < supports < std::less < > ( _Tp, _Up ) >::value >::type * = nullptr >
auto operator ( ) ( _Tp && __t, _Up && __u ) const noexcept ( noexcept ( std::forward < _Tp > ( __t ) < std::forward < _Up > ( __u ) ) ) -> decltype ( std::forward < _Tp > ( __t ) < std::forward < _Up > ( __u ) ) {
return std::forward < _Tp > ( __t ) < std::forward < _Up > ( __u );
}
template < typename _Tp, typename _Up, typename std::enable_if < ! supports < std::less < > ( _Tp, _Up ) >::value >::type * = nullptr >
bool operator ( ) ( _Tp &&, _Up && ) const noexcept {
return ext::type_index ( typeid ( _Tp ) ) < ext::type_index ( typeid ( _Up ) );
}
typedef std::__is_transparent is_transparent;
};
/**
* \brief
* Class extending the reference wrapper class from the standard library. Original reason is to allow its use with standard stream aggregation class.
......
#include "FunctionalTest.h"
#include <alib/functional>
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FunctionalTest, "bits" );
CPPUNIT_TEST_SUITE_REGISTRATION( FunctionalTest );
void FunctionalTest::setUp() {
}
void FunctionalTest::tearDown() {
}
void FunctionalTest::testLess() {
ext::less < > test;
CPPUNIT_ASSERT ( test ( 1, 2 ) == true );
CPPUNIT_ASSERT ( test ( 1, 2. ) == true );
CPPUNIT_EXCLUSIVE_OR( test ( std::string ( "aa" ), 1 ), test ( 1, std::string ( "aa" ) ) );
}
#ifndef FUNCTIONAL_TEST_H_
#define FUNCTIONAL_TEST_H_
#include <cppunit/extensions/HelperMacros.h>
class FunctionalTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( FunctionalTest );
CPPUNIT_TEST( testLess );
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void testLess();
};
#endif // FUNCTIONAL_TEST_H_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment