Skip to content

Commit d8c1e84

Browse files
committed
Conan support, next version
1 parent a6b31bd commit d8c1e84

File tree

8 files changed

+305
-27
lines changed

8 files changed

+305
-27
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ matrix:
172172
- CXX=clang++
173173

174174
- os: osx
175-
osx_image: xcode9.2
175+
osx_image: xcode9.3
176176
compiler: clang
177177
env:
178178
- CXX=clang++

CMakeLists.txt

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
cmake_minimum_required (VERSION 3.2.0 FATAL_ERROR)
22

3-
project (taocpp-operators VERSION 1.0.0 LANGUAGES CXX)
3+
project (taocpp-operators VERSION 1.0.2 LANGUAGES CXX)
44

5-
set (CMAKE_CXX_STANDARD 11)
6-
set (CMAKE_CXX_STANDARD_REQUIRED ON)
5+
# installation directories
6+
set (TAOCPP_OPERATORS_INSTALL_INCLUDE_DIR "include" CACHE STRING "The installation include directory")
7+
set (TAOCPP_OPERATORS_INSTALL_DOC_DIR "share/doc/tao/operators" CACHE STRING "The installation doc directory")
8+
set (TAOCPP_OPERATORS_INSTALL_CMAKE_DIR "share/tao/operators/cmake" CACHE STRING "The installation cmake directory")
9+
10+
# define a header-only library
11+
add_library (taocpp-operators INTERFACE)
12+
add_library (taocpp::operators ALIAS taocpp-operators)
13+
target_include_directories (taocpp-operators INTERFACE
14+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
15+
$<INSTALL_INTERFACE:${TAOCPP_OPERATORS_INSTALL_INCLUDE_DIR}>
16+
)
717

8-
# taocpp/operators
9-
include ("taocpp-operators.cmake")
10-
include_directories (${TAOCPP_OPERATORS_INCLUDE_DIRS})
18+
# features used by taocpp/operators
19+
target_compile_features (${TAOCPP_OPERATORS_LIBRARY} INTERFACE
20+
cxx_noexcept
21+
cxx_rvalue_references
22+
)
1123

1224
# testing
1325
enable_testing ()
@@ -16,10 +28,14 @@ if (TAOCPP_OPERATORS_BUILD_TESTS)
1628
add_subdirectory (src/test/operators)
1729
endif ()
1830

19-
# installation directories
20-
set (TAOCPP_OPERATORS_INSTALL_INCLUDE_DIR "include" CACHE STRING "The installation include directory")
21-
set (TAOCPP_OPERATORS_INSTALL_DOC_DIR "share/doc/tao/operators" CACHE STRING "The installation doc directory")
31+
# install and export target
32+
install (TARGETS taocpp-operators EXPORT taocpp-operators-targets)
33+
34+
install (EXPORT taocpp-operators-targets
35+
FILE taocpp-operators-config.cmake
36+
NAMESPACE taocpp::
37+
DESTINATION ${TAOCPP_OPERATORS_INSTALL_CMAKE_DIR}
38+
)
2239

23-
# install
2440
install (DIRECTORY include/ DESTINATION ${TAOCPP_OPERATORS_INSTALL_INCLUDE_DIR})
2541
install (FILES LICENSE DESTINATION ${TAOCPP_OPERATORS_INSTALL_DOC_DIR})

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# The Art of C++ / Operators
22

33
[![Release](https://img.shields.io/github/release/taocpp/operators.svg)](https://github.com/taocpp/operators/releases/latest)
4+
[![Download](https://api.bintray.com/packages/taocpp/public-conan/taocpp-operators%3Ataocpp/images/download.svg)](https://bintray.com/taocpp/public-conan/taocpp-operators%3Ataocpp/_latestVersion)
45
[![TravisCI](https://travis-ci.org/taocpp/operators.svg?branch=master)](https://travis-ci.org/taocpp/operators)
56
[![AppVeyor](https://ci.appveyor.com/api/projects/status/794d875ucgic4sq0/branch/master?svg=true)](https://ci.appveyor.com/project/taocpp/operators)
67
[![Coverage](https://coveralls.io/repos/github/taocpp/operators/badge.svg?branch=master)](https://coveralls.io/github/taocpp/operators)
@@ -121,6 +122,8 @@ Remember to enable C++11, e.g., provide `-std=c++11` or similar options.
121122
The Art of C++ / Operators is a single-header library. There is nothing to build or install,
122123
just copy the header somewhere and include it in your code.
123124

125+
[Conan packages](https://bintray.com/taocpp/public-conan/taocpp-operators%3Ataocpp) are available.
126+
124127
## Provided Templates
125128

126129
The following table gives an overview of the available templates.
@@ -896,6 +899,13 @@ With this little hack, The Art of C++ / Operators can be used with GCC 4.4+.
896899

897900
## Changelog
898901

902+
### 1.0.2
903+
904+
Released 2018-06-05
905+
906+
* Improve CMake support.
907+
* Conan support.
908+
899909
### 1.0.1
900910

901911
Released 2018-04-23

conanfile.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from conans import ConanFile, CMake
2+
import os
3+
4+
class TAOCPPOperatorsConan(ConanFile):
5+
name = "taocpp-operators"
6+
description = "C++11 single-header library that provides highly efficient, move aware operators for arithmetic data types"
7+
homepage = "https://github.com/taocpp/operators"
8+
url = homepage
9+
license = "MIT"
10+
author = "[email protected]"
11+
exports_sources = "include*", "LICENSE", "CMakeLists.txt"
12+
13+
def package(self):
14+
cmake = CMake(self)
15+
16+
cmake.definitions["TAOCPP_OPERATORS_BUILD_TESTS"] = "OFF"
17+
cmake.definitions["TAOCPP_OPERATORS_BUILD_EXAMPLES"] = "OFF"
18+
cmake.definitions["TAOCPP_OPERATORS_INSTALL_DOC_DIR"] = "licenses"
19+
20+
cmake.configure()
21+
cmake.install()
22+
23+
def package_id(self):
24+
self.info.header_only()

taocpp-operators.cmake

Lines changed: 0 additions & 16 deletions
This file was deleted.

test_package/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
project(test_package)
2+
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR)
3+
4+
set(CMAKE_VERBOSE_MAKEFILE TRUE)
5+
6+
set(CMAKE_CXX_STANDARD 11)
7+
8+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
9+
conan_basic_setup()
10+
11+
file(GLOB SOURCE_FILES *.cpp)
12+
13+
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
14+
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})

test_package/conanfile.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from conans import ConanFile, CMake, tools, RunEnvironment
5+
import os
6+
7+
class TestPackageConan(ConanFile):
8+
settings = "os", "compiler", "build_type", "arch"
9+
generators = "cmake"
10+
11+
def build(self):
12+
cmake = CMake(self)
13+
cmake.configure()
14+
cmake.build()
15+
16+
def test(self):
17+
with tools.environment_append(RunEnvironment(self).vars):
18+
bin_path = os.path.join("bin", "test_package")
19+
self.run('{}'.format(bin_path))

test_package/test_package.cpp

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
// The Art of C++ / Operators
2+
// Copyright (c) 2013-2018 Daniel Frey
3+
// Please see LICENSE for license or visit https://github.com/taocpp/operators/
4+
5+
#include <tao/operators.hpp>
6+
7+
#include <cassert>
8+
#include <type_traits>
9+
10+
class X
11+
: tao::operators::ordered_field< X >,
12+
tao::operators::modable< X >,
13+
tao::operators::ordered_field< X, int >,
14+
tao::operators::modable< X, int >
15+
{
16+
public:
17+
explicit X( const int v ) noexcept
18+
: v_( v )
19+
{
20+
}
21+
22+
X( const X& ) = default;
23+
X( X&& ) = default;
24+
25+
~X() = default;
26+
27+
X& operator=( const X& ) = delete;
28+
X& operator=( X&& ) = delete;
29+
30+
X& operator+=( const X& x ) noexcept
31+
{
32+
v_ += x.v_;
33+
return *this;
34+
}
35+
36+
X& operator-=( const X& x )
37+
{
38+
v_ -= x.v_;
39+
return *this;
40+
}
41+
42+
X& operator*=( const X& x )
43+
{
44+
v_ *= x.v_;
45+
return *this;
46+
}
47+
48+
X& operator/=( const X& x )
49+
{
50+
v_ /= x.v_;
51+
return *this;
52+
}
53+
54+
X& operator%=( const X& x )
55+
{
56+
v_ %= x.v_;
57+
return *this;
58+
}
59+
60+
X& operator+=( const int v )
61+
{
62+
v_ += v;
63+
return *this;
64+
}
65+
66+
X& operator-=( const int v )
67+
{
68+
v_ -= v;
69+
return *this;
70+
}
71+
72+
X& operator*=( const int v )
73+
{
74+
v_ *= v;
75+
return *this;
76+
}
77+
78+
X& operator/=( const int v )
79+
{
80+
v_ /= v;
81+
return *this;
82+
}
83+
84+
X& operator%=( const int v )
85+
{
86+
v_ %= v;
87+
return *this;
88+
}
89+
90+
int v_;
91+
};
92+
93+
bool operator==( const X& lhs, const X& rhs )
94+
{
95+
return lhs.v_ == rhs.v_;
96+
}
97+
98+
bool operator<( const X& lhs, const X& rhs )
99+
{
100+
return lhs.v_ < rhs.v_;
101+
}
102+
103+
bool operator==( const X& x, const int v )
104+
{
105+
return x.v_ == v;
106+
}
107+
108+
bool operator<( const X& x, const int v )
109+
{
110+
return x.v_ < v;
111+
}
112+
113+
bool operator>( const X& x, const int v )
114+
{
115+
return x.v_ > v;
116+
}
117+
118+
class E
119+
: tao::operators::ordered_field< E >
120+
{
121+
};
122+
123+
void adl_test( const E& /*unused*/ ) {}
124+
125+
namespace tao
126+
{
127+
void adl_test( const E& );
128+
129+
} // namespace tao
130+
131+
struct S
132+
: tao::operators::addable< S >
133+
{
134+
S() = default;
135+
136+
S( const S& a, const S& b )
137+
: S( a + b )
138+
{
139+
}
140+
141+
S& operator+=( const S& /*unused*/ ) noexcept
142+
{
143+
return *this;
144+
}
145+
};
146+
147+
int main()
148+
{
149+
X x1( 1 );
150+
X x2( 2 );
151+
X x3( 3 );
152+
153+
static_assert( noexcept( x1 + x2 ), "oops" );
154+
static_assert( !noexcept( x1 * x2 ), "oops" );
155+
156+
assert( x1 == x1 );
157+
assert( x1 != x2 );
158+
159+
assert( x1 == 1 );
160+
assert( 2 == x2 );
161+
assert( x3 != 1 );
162+
assert( 2 != x3 );
163+
164+
assert( x1 < x2 );
165+
assert( x1 <= x2 );
166+
assert( x2 <= x2 );
167+
assert( x3 > x2 );
168+
assert( x3 >= x2 );
169+
assert( x2 >= x2 );
170+
171+
assert( x1 < 2 );
172+
assert( x1 <= 2 );
173+
assert( x2 <= 2 );
174+
assert( x3 > 2 );
175+
assert( x3 >= 2 );
176+
assert( x2 >= 2 );
177+
178+
assert( 1 < x2 );
179+
assert( 1 <= x2 );
180+
assert( 2 <= x2 );
181+
assert( 3 > x2 );
182+
assert( 3 >= x2 );
183+
assert( 2 >= x2 );
184+
185+
assert( x1 + x2 == x3 );
186+
assert( 1 + x2 == x3 );
187+
assert( x1 + 2 == x3 );
188+
assert( x2 + x1 == 3 );
189+
190+
assert( x3 - x1 == x2 );
191+
assert( 3 - x1 == x2 );
192+
assert( x3 - 1 == x2 );
193+
assert( x1 - x3 == -2 );
194+
195+
assert( x2 * x2 == 4 );
196+
assert( x2 * 3 == 6 );
197+
assert( 4 * x2 == 8 );
198+
199+
assert( ( x3 + x1 ) / x2 == 2 );
200+
assert( ( x1 + x3 ) / 2 == x2 );
201+
202+
assert( x3 % x2 == 1 );
203+
assert( x3 % 2 == 1 );
204+
205+
static_assert( std::is_empty< E >::value, "oops" );
206+
207+
adl_test( E{} );
208+
209+
S s;
210+
S s2( s, s );
211+
}

0 commit comments

Comments
 (0)