Skip to content

Commit

Permalink
Conan support, next version
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Jun 5, 2018
1 parent a6b31bd commit d8c1e84
Show file tree
Hide file tree
Showing 8 changed files with 305 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ matrix:
- CXX=clang++

- os: osx
osx_image: xcode9.2
osx_image: xcode9.3
compiler: clang
env:
- CXX=clang++
Expand Down
36 changes: 26 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
cmake_minimum_required (VERSION 3.2.0 FATAL_ERROR)

project (taocpp-operators VERSION 1.0.0 LANGUAGES CXX)
project (taocpp-operators VERSION 1.0.2 LANGUAGES CXX)

set (CMAKE_CXX_STANDARD 11)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
# installation directories
set (TAOCPP_OPERATORS_INSTALL_INCLUDE_DIR "include" CACHE STRING "The installation include directory")
set (TAOCPP_OPERATORS_INSTALL_DOC_DIR "share/doc/tao/operators" CACHE STRING "The installation doc directory")
set (TAOCPP_OPERATORS_INSTALL_CMAKE_DIR "share/tao/operators/cmake" CACHE STRING "The installation cmake directory")

# define a header-only library
add_library (taocpp-operators INTERFACE)
add_library (taocpp::operators ALIAS taocpp-operators)
target_include_directories (taocpp-operators INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${TAOCPP_OPERATORS_INSTALL_INCLUDE_DIR}>
)

# taocpp/operators
include ("taocpp-operators.cmake")
include_directories (${TAOCPP_OPERATORS_INCLUDE_DIRS})
# features used by taocpp/operators
target_compile_features (${TAOCPP_OPERATORS_LIBRARY} INTERFACE
cxx_noexcept
cxx_rvalue_references
)

# testing
enable_testing ()
Expand All @@ -16,10 +28,14 @@ if (TAOCPP_OPERATORS_BUILD_TESTS)
add_subdirectory (src/test/operators)
endif ()

# installation directories
set (TAOCPP_OPERATORS_INSTALL_INCLUDE_DIR "include" CACHE STRING "The installation include directory")
set (TAOCPP_OPERATORS_INSTALL_DOC_DIR "share/doc/tao/operators" CACHE STRING "The installation doc directory")
# install and export target
install (TARGETS taocpp-operators EXPORT taocpp-operators-targets)

install (EXPORT taocpp-operators-targets
FILE taocpp-operators-config.cmake
NAMESPACE taocpp::
DESTINATION ${TAOCPP_OPERATORS_INSTALL_CMAKE_DIR}
)

# install
install (DIRECTORY include/ DESTINATION ${TAOCPP_OPERATORS_INSTALL_INCLUDE_DIR})
install (FILES LICENSE DESTINATION ${TAOCPP_OPERATORS_INSTALL_DOC_DIR})
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# The Art of C++ / Operators

[![Release](https://img.shields.io/github/release/taocpp/operators.svg)](https://github.com/taocpp/operators/releases/latest)
[![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)
[![TravisCI](https://travis-ci.org/taocpp/operators.svg?branch=master)](https://travis-ci.org/taocpp/operators)
[![AppVeyor](https://ci.appveyor.com/api/projects/status/794d875ucgic4sq0/branch/master?svg=true)](https://ci.appveyor.com/project/taocpp/operators)
[![Coverage](https://coveralls.io/repos/github/taocpp/operators/badge.svg?branch=master)](https://coveralls.io/github/taocpp/operators)
Expand Down Expand Up @@ -121,6 +122,8 @@ Remember to enable C++11, e.g., provide `-std=c++11` or similar options.
The Art of C++ / Operators is a single-header library. There is nothing to build or install,
just copy the header somewhere and include it in your code.

[Conan packages](https://bintray.com/taocpp/public-conan/taocpp-operators%3Ataocpp) are available.

## Provided Templates

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

## Changelog

### 1.0.2

Released 2018-06-05

* Improve CMake support.
* Conan support.

### 1.0.1

Released 2018-04-23
Expand Down
24 changes: 24 additions & 0 deletions conanfile.py
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()
16 changes: 0 additions & 16 deletions taocpp-operators.cmake

This file was deleted.

14 changes: 14 additions & 0 deletions test_package/CMakeLists.txt
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})
19 changes: 19 additions & 0 deletions test_package/conanfile.py
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))
211 changes: 211 additions & 0 deletions test_package/test_package.cpp
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 );
}

0 comments on commit d8c1e84

Please sign in to comment.