-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
305 additions
and
27 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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from conans import ConanFile, CMake | ||
import os | ||
|
||
class TAOCPPOperatorsConan(ConanFile): | ||
name = "taocpp-operators" | ||
description = "C++11 single-header library that provides highly efficient, move aware operators for arithmetic data types" | ||
homepage = "https://github.com/taocpp/operators" | ||
url = homepage | ||
license = "MIT" | ||
author = "taocpp@icemx.net" | ||
exports_sources = "include*", "LICENSE", "CMakeLists.txt" | ||
|
||
def package(self): | ||
cmake = CMake(self) | ||
|
||
cmake.definitions["TAOCPP_OPERATORS_BUILD_TESTS"] = "OFF" | ||
cmake.definitions["TAOCPP_OPERATORS_BUILD_EXAMPLES"] = "OFF" | ||
cmake.definitions["TAOCPP_OPERATORS_INSTALL_DOC_DIR"] = "licenses" | ||
|
||
cmake.configure() | ||
cmake.install() | ||
|
||
def package_id(self): | ||
self.info.header_only() |
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
project(test_package) | ||
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR) | ||
|
||
set(CMAKE_VERBOSE_MAKEFILE TRUE) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
|
||
file(GLOB SOURCE_FILES *.cpp) | ||
|
||
add_executable(${PROJECT_NAME} ${SOURCE_FILES}) | ||
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) |
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,19 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from conans import ConanFile, CMake, tools, RunEnvironment | ||
import os | ||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake" | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
with tools.environment_append(RunEnvironment(self).vars): | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run('{}'.format(bin_path)) |
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,211 @@ | ||
// The Art of C++ / Operators | ||
// Copyright (c) 2013-2018 Daniel Frey | ||
// Please see LICENSE for license or visit https://github.com/taocpp/operators/ | ||
|
||
#include <tao/operators.hpp> | ||
|
||
#include <cassert> | ||
#include <type_traits> | ||
|
||
class X | ||
: tao::operators::ordered_field< X >, | ||
tao::operators::modable< X >, | ||
tao::operators::ordered_field< X, int >, | ||
tao::operators::modable< X, int > | ||
{ | ||
public: | ||
explicit X( const int v ) noexcept | ||
: v_( v ) | ||
{ | ||
} | ||
|
||
X( const X& ) = default; | ||
X( X&& ) = default; | ||
|
||
~X() = default; | ||
|
||
X& operator=( const X& ) = delete; | ||
X& operator=( X&& ) = delete; | ||
|
||
X& operator+=( const X& x ) noexcept | ||
{ | ||
v_ += x.v_; | ||
return *this; | ||
} | ||
|
||
X& operator-=( const X& x ) | ||
{ | ||
v_ -= x.v_; | ||
return *this; | ||
} | ||
|
||
X& operator*=( const X& x ) | ||
{ | ||
v_ *= x.v_; | ||
return *this; | ||
} | ||
|
||
X& operator/=( const X& x ) | ||
{ | ||
v_ /= x.v_; | ||
return *this; | ||
} | ||
|
||
X& operator%=( const X& x ) | ||
{ | ||
v_ %= x.v_; | ||
return *this; | ||
} | ||
|
||
X& operator+=( const int v ) | ||
{ | ||
v_ += v; | ||
return *this; | ||
} | ||
|
||
X& operator-=( const int v ) | ||
{ | ||
v_ -= v; | ||
return *this; | ||
} | ||
|
||
X& operator*=( const int v ) | ||
{ | ||
v_ *= v; | ||
return *this; | ||
} | ||
|
||
X& operator/=( const int v ) | ||
{ | ||
v_ /= v; | ||
return *this; | ||
} | ||
|
||
X& operator%=( const int v ) | ||
{ | ||
v_ %= v; | ||
return *this; | ||
} | ||
|
||
int v_; | ||
}; | ||
|
||
bool operator==( const X& lhs, const X& rhs ) | ||
{ | ||
return lhs.v_ == rhs.v_; | ||
} | ||
|
||
bool operator<( const X& lhs, const X& rhs ) | ||
{ | ||
return lhs.v_ < rhs.v_; | ||
} | ||
|
||
bool operator==( const X& x, const int v ) | ||
{ | ||
return x.v_ == v; | ||
} | ||
|
||
bool operator<( const X& x, const int v ) | ||
{ | ||
return x.v_ < v; | ||
} | ||
|
||
bool operator>( const X& x, const int v ) | ||
{ | ||
return x.v_ > v; | ||
} | ||
|
||
class E | ||
: tao::operators::ordered_field< E > | ||
{ | ||
}; | ||
|
||
void adl_test( const E& /*unused*/ ) {} | ||
|
||
namespace tao | ||
{ | ||
void adl_test( const E& ); | ||
|
||
} // namespace tao | ||
|
||
struct S | ||
: tao::operators::addable< S > | ||
{ | ||
S() = default; | ||
|
||
S( const S& a, const S& b ) | ||
: S( a + b ) | ||
{ | ||
} | ||
|
||
S& operator+=( const S& /*unused*/ ) noexcept | ||
{ | ||
return *this; | ||
} | ||
}; | ||
|
||
int main() | ||
{ | ||
X x1( 1 ); | ||
X x2( 2 ); | ||
X x3( 3 ); | ||
|
||
static_assert( noexcept( x1 + x2 ), "oops" ); | ||
static_assert( !noexcept( x1 * x2 ), "oops" ); | ||
|
||
assert( x1 == x1 ); | ||
assert( x1 != x2 ); | ||
|
||
assert( x1 == 1 ); | ||
assert( 2 == x2 ); | ||
assert( x3 != 1 ); | ||
assert( 2 != x3 ); | ||
|
||
assert( x1 < x2 ); | ||
assert( x1 <= x2 ); | ||
assert( x2 <= x2 ); | ||
assert( x3 > x2 ); | ||
assert( x3 >= x2 ); | ||
assert( x2 >= x2 ); | ||
|
||
assert( x1 < 2 ); | ||
assert( x1 <= 2 ); | ||
assert( x2 <= 2 ); | ||
assert( x3 > 2 ); | ||
assert( x3 >= 2 ); | ||
assert( x2 >= 2 ); | ||
|
||
assert( 1 < x2 ); | ||
assert( 1 <= x2 ); | ||
assert( 2 <= x2 ); | ||
assert( 3 > x2 ); | ||
assert( 3 >= x2 ); | ||
assert( 2 >= x2 ); | ||
|
||
assert( x1 + x2 == x3 ); | ||
assert( 1 + x2 == x3 ); | ||
assert( x1 + 2 == x3 ); | ||
assert( x2 + x1 == 3 ); | ||
|
||
assert( x3 - x1 == x2 ); | ||
assert( 3 - x1 == x2 ); | ||
assert( x3 - 1 == x2 ); | ||
assert( x1 - x3 == -2 ); | ||
|
||
assert( x2 * x2 == 4 ); | ||
assert( x2 * 3 == 6 ); | ||
assert( 4 * x2 == 8 ); | ||
|
||
assert( ( x3 + x1 ) / x2 == 2 ); | ||
assert( ( x1 + x3 ) / 2 == x2 ); | ||
|
||
assert( x3 % x2 == 1 ); | ||
assert( x3 % 2 == 1 ); | ||
|
||
static_assert( std::is_empty< E >::value, "oops" ); | ||
|
||
adl_test( E{} ); | ||
|
||
S s; | ||
S s2( s, s ); | ||
} |