Skip to content

Commit ee489cb

Browse files
committed
General update
1 parent 146c949 commit ee489cb

File tree

8 files changed

+771
-714
lines changed

8 files changed

+771
-714
lines changed

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,13 @@ matrix:
117117
- CXX=clang++
118118

119119
- os: osx
120-
osx_image: xcode8.2
120+
osx_image: xcode8.3
121+
compiler: clang
122+
env:
123+
- CXX=clang++
124+
125+
- os: osx
126+
osx_image: xcode9.2
121127
compiler: clang
122128
env:
123129
- CXX=clang++

CMakeLists.txt

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

3-
# set project and version
43
project (taocpp-operators VERSION 1.0.0 LANGUAGES CXX)
54

6-
# define a header-only library
7-
add_library (taocpp-operators INTERFACE)
8-
add_library (taocpp::operators ALIAS taocpp-operators)
9-
target_include_directories (taocpp-operators INTERFACE
10-
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
11-
$<INSTALL_INTERFACE:include>
12-
)
5+
set (CMAKE_CXX_STANDARD 11)
6+
set (CMAKE_CXX_STANDARD_REQUIRED ON)
137

14-
# features used by taocpp/operators
15-
target_compile_features (taocpp-operators INTERFACE
16-
cxx_noexcept
17-
cxx_rvalue_references
18-
)
8+
# taocpp/operators
9+
include ("taocpp-operators.cmake")
10+
include_directories (${TAOCPP_OPERATORS_INCLUDE_DIRS})
1911

2012
# testing
2113
enable_testing ()

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2013-2017 Daniel Frey
3+
Copyright (c) 2013-2018 Daniel Frey
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The Art of C++ / Operators is a zero-dependency C++11 single-header library that
2424
## Preface
2525

2626
The Art of C++ / Operators is the next logical step in the evolution of the
27-
[Boost.Operators](http://www.boost.org/doc/libs/1_53_0/libs/utility/operators.htm) library,
27+
[Boost.Operators](http://www.boost.org/doc/libs/1_66_0/libs/utility/operators.htm) library,
2828
whose maintainer I became in 2002. Since then, C++ has changed significiantly and
2929
with C++11, the time has come for a complete rewrite and to get rid of some
3030
*very* old legacy code and work-arounds.
@@ -850,7 +850,7 @@ With this little hack, The Art of C++ / Operators can be used with GCC 4.4+.
850850
851851
The Art of C++ is certified [Open Source](http://www.opensource.org/docs/definition.html) software. It may be used for any purpose, including commercial purposes, at absolutely no cost. It is distributed under the terms of the [MIT license](http://www.opensource.org/licenses/mit-license.html) reproduced here.
852852
853-
> Copyright (c) 2013-2017 Daniel Frey
853+
> Copyright (c) 2013-2018 Daniel Frey
854854
>
855855
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
856856
>

include/tao/operators.hpp

Lines changed: 563 additions & 605 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// The Art of C++ / Operators
2-
// Copyright (c) 2013-2016 Daniel Frey
2+
// Copyright (c) 2013-2018 Daniel Frey
33
// Please see LICENSE for license or visit https://github.com/taocpp/operators/
44

5-
#define TAOCPP_NO_RVALUE_REFERENCE_RESULTS
5+
#define TAO_NO_RVALUE_REFERENCE_RESULTS
66
#include "operators.cpp"

src/test/operators/operators.cpp

Lines changed: 175 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// The Art of C++ / Operators
2-
// Copyright (c) 2013-2017 Daniel Frey
2+
// Copyright (c) 2013-2018 Daniel Frey
33
// Please see LICENSE for license or visit https://github.com/taocpp/operators/
44

55
#include <tao/operators.hpp>
@@ -8,118 +8,203 @@
88
#include <type_traits>
99

1010
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 >
11+
: tao::operators::ordered_field< X >,
12+
tao::operators::modable< X >,
13+
tao::operators::ordered_field< X, int >,
14+
tao::operators::modable< X, int >
1515
{
1616
public:
17-
explicit X( const int v ) noexcept : v_( v ) {}
18-
19-
X( const X& x ) noexcept : v_( x.v_ ) {}
17+
explicit X( const int v ) noexcept
18+
: v_( v )
19+
{
20+
}
21+
22+
X( const X& x )
23+
noexcept
24+
: v_( x.v_ )
25+
{
26+
}
27+
28+
X& operator+=( const X& x ) noexcept
29+
{
30+
v_ += x.v_;
31+
return *this;
32+
}
33+
34+
X& operator-=( const X& x )
35+
{
36+
v_ -= x.v_;
37+
return *this;
38+
}
39+
40+
X& operator*=( const X& x )
41+
{
42+
v_ *= x.v_;
43+
return *this;
44+
}
45+
46+
X& operator/=( const X& x )
47+
{
48+
v_ /= x.v_;
49+
return *this;
50+
}
51+
52+
X& operator%=( const X& x )
53+
{
54+
v_ %= x.v_;
55+
return *this;
56+
}
57+
58+
X& operator+=( const int v )
59+
{
60+
v_ += v;
61+
return *this;
62+
}
63+
64+
X& operator-=( const int v )
65+
{
66+
v_ -= v;
67+
return *this;
68+
}
69+
70+
X& operator*=( const int v )
71+
{
72+
v_ *= v;
73+
return *this;
74+
}
75+
76+
X& operator/=( const int v )
77+
{
78+
v_ /= v;
79+
return *this;
80+
}
81+
82+
X& operator%=( const int v )
83+
{
84+
v_ %= v;
85+
return *this;
86+
}
87+
88+
int v_;
89+
};
2090

21-
X& operator+=( const X& x ) noexcept { v_ += x.v_; return *this; }
22-
X& operator-=( const X& x ) { v_ -= x.v_; return *this; }
23-
X& operator*=( const X& x ) { v_ *= x.v_; return *this; }
24-
X& operator/=( const X& x ) { v_ /= x.v_; return *this; }
25-
X& operator%=( const X& x ) { v_ %= x.v_; return *this; }
91+
bool operator==( const X& lhs, const X& rhs )
92+
{
93+
return lhs.v_ == rhs.v_;
94+
}
2695

27-
X& operator+=( const int v ) { v_ += v; return *this; }
28-
X& operator-=( const int v ) { v_ -= v; return *this; }
29-
X& operator*=( const int v ) { v_ *= v; return *this; }
30-
X& operator/=( const int v ) { v_ /= v; return *this; }
31-
X& operator%=( const int v ) { v_ %= v; return *this; }
96+
bool operator<( const X& lhs, const X& rhs )
97+
{
98+
return lhs.v_ < rhs.v_;
99+
}
32100

33-
int v_;
34-
};
101+
bool operator==( const X& x, const int v )
102+
{
103+
return x.v_ == v;
104+
}
35105

36-
bool operator==( const X& lhs, const X& rhs ) { return lhs.v_ == rhs.v_; }
37-
bool operator<( const X& lhs, const X& rhs ) { return lhs.v_ < rhs.v_; }
106+
bool operator<( const X& x, const int v )
107+
{
108+
return x.v_ < v;
109+
}
38110

39-
bool operator==( const X& x, const int v ) { return x.v_ == v; }
40-
bool operator<( const X& x, const int v ) { return x.v_ < v; }
41-
bool operator>( const X& x, const int v ) { return x.v_ > v; }
111+
bool operator>( const X& x, const int v )
112+
{
113+
return x.v_ > v;
114+
}
42115

43-
class E : tao::operators::ordered_field< E > {};
116+
class E
117+
: tao::operators::ordered_field< E >
118+
{
119+
};
44120

45121
void adl_test( const E& ) {}
46122

47123
namespace tao
48124
{
49-
void adl_test( const E& );
125+
void adl_test( const E& );
50126
}
51127

52-
struct S : tao::operators::addable< S >
128+
struct S
129+
: tao::operators::addable< S >
53130
{
54-
S() {}
55-
S( const S& a, const S& b ) : S( a + b ) {}
56-
S& operator+=( const S& ) noexcept { return *this; }
131+
S() {}
132+
133+
S( const S& a, const S& b )
134+
: S( a + b )
135+
{
136+
}
137+
138+
S& operator+=( const S& ) noexcept
139+
{
140+
return *this;
141+
}
57142
};
58143

59144
int main()
60145
{
61-
X x1( 1 );
62-
X x2( 2 );
63-
X x3( 3 );
64-
65-
static_assert( noexcept( x1 + x2 ), "oops" );
66-
static_assert( !noexcept( x1 * x2 ), "oops" );
67-
68-
assert( x1 == x1 );
69-
assert( x1 != x2 );
70-
71-
assert( x1 == 1 );
72-
assert( 2 == x2 );
73-
assert( x3 != 1 );
74-
assert( 2 != x3 );
75-
76-
assert( x1 < x2 );
77-
assert( x1 <= x2 );
78-
assert( x2 <= x2 );
79-
assert( x3 > x2 );
80-
assert( x3 >= x2 );
81-
assert( x2 >= x2 );
82-
83-
assert( x1 < 2 );
84-
assert( x1 <= 2 );
85-
assert( x2 <= 2 );
86-
assert( x3 > 2 );
87-
assert( x3 >= 2 );
88-
assert( x2 >= 2 );
89-
90-
assert( 1 < x2 );
91-
assert( 1 <= x2 );
92-
assert( 2 <= x2 );
93-
assert( 3 > x2 );
94-
assert( 3 >= x2 );
95-
assert( 2 >= x2 );
96-
97-
assert( x1 + x2 == x3 );
98-
assert( 1 + x2 == x3 );
99-
assert( x1 + 2 == x3 );
100-
assert( x2 + x1 == 3 );
101-
102-
assert( x3 - x1 == x2 );
103-
assert( 3 - x1 == x2 );
104-
assert( x3 - 1 == x2 );
105-
assert( x1 - x3 == -2 );
106-
107-
assert( x2 * x2 == 4 );
108-
assert( x2 * 3 == 6 );
109-
assert( 4 * x2 == 8 );
110-
111-
assert( ( x3 + x1 ) / x2 == 2 );
112-
assert( ( x1 + x3 ) / 2 == x2 );
113-
114-
assert( x3 % x2 == 1 );
115-
assert( x3 % 2 == 1 );
146+
X x1( 1 );
147+
X x2( 2 );
148+
X x3( 3 );
149+
150+
static_assert( noexcept( x1 + x2 ), "oops" );
151+
static_assert( !noexcept( x1 * x2 ), "oops" );
152+
153+
assert( x1 == x1 );
154+
assert( x1 != x2 );
155+
156+
assert( x1 == 1 );
157+
assert( 2 == x2 );
158+
assert( x3 != 1 );
159+
assert( 2 != x3 );
160+
161+
assert( x1 < x2 );
162+
assert( x1 <= x2 );
163+
assert( x2 <= x2 );
164+
assert( x3 > x2 );
165+
assert( x3 >= x2 );
166+
assert( x2 >= x2 );
167+
168+
assert( x1 < 2 );
169+
assert( x1 <= 2 );
170+
assert( x2 <= 2 );
171+
assert( x3 > 2 );
172+
assert( x3 >= 2 );
173+
assert( x2 >= 2 );
174+
175+
assert( 1 < x2 );
176+
assert( 1 <= x2 );
177+
assert( 2 <= x2 );
178+
assert( 3 > x2 );
179+
assert( 3 >= x2 );
180+
assert( 2 >= x2 );
181+
182+
assert( x1 + x2 == x3 );
183+
assert( 1 + x2 == x3 );
184+
assert( x1 + 2 == x3 );
185+
assert( x2 + x1 == 3 );
186+
187+
assert( x3 - x1 == x2 );
188+
assert( 3 - x1 == x2 );
189+
assert( x3 - 1 == x2 );
190+
assert( x1 - x3 == -2 );
191+
192+
assert( x2 * x2 == 4 );
193+
assert( x2 * 3 == 6 );
194+
assert( 4 * x2 == 8 );
195+
196+
assert( ( x3 + x1 ) / x2 == 2 );
197+
assert( ( x1 + x3 ) / 2 == x2 );
198+
199+
assert( x3 % x2 == 1 );
200+
assert( x3 % 2 == 1 );
116201

117202
#ifndef _WIN32
118-
static_assert( std::is_empty< E >::value, "oops" );
203+
static_assert( std::is_empty< E >::value, "oops" );
119204
#endif
120205

121-
adl_test( E() );
206+
adl_test( E{} );
122207

123-
S s;
124-
S s2( s, s );
208+
S s;
209+
S s2( s, s );
125210
}

taocpp-operators.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
set (TAOCPP_OPERATORS_LIBRARY taocpp-operators)
2+
set (TAOCPP_OPERATORS_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/include)
3+
4+
file (GLOB_RECURSE TAOCPP_OPERATORS_INCLUDE_FILES ${TAOCPP_OPERATORS_INCLUDE_DIRS}/*.hpp)
5+
6+
source_group ("Header Files" FILES ${TAOCPP_OPERATORS_INCLUDE_FILES})
7+
8+
add_library (${TAOCPP_OPERATORS_LIBRARY} INTERFACE)
9+
add_library (taocpp::operators ALIAS ${TAOCPP_OPERATORS_LIBRARY})
10+
11+
target_include_directories (${TAOCPP_OPERATORS_LIBRARY} INTERFACE ${TAOCPP_OPERATORS_INCLUDE_DIRS})
12+
13+
target_compile_features (${TAOCPP_OPERATORS_LIBRARY} INTERFACE
14+
cxx_noexcept
15+
cxx_rvalue_references
16+
)

0 commit comments

Comments
 (0)