Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add think-cell-library #23777

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions recipes/think-cell-library/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"cci.20240426":
url: "https://github.com/think-cell/think-cell-library/archive/9b334a494d66c76352e66d6440c0116be7bce8a1.tar.gz"
sha256: "886e0a49f5ff7c978362511ca3d3123d8f98478aad2445950842d3e1388e5c7b"
73 changes: 73 additions & 0 deletions recipes/think-cell-library/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.files import copy, get
from conan.tools.layout import basic_layout
from conan.tools.scm import Version
import os


required_conan_version = ">=1.53.0"


class PackageConan(ConanFile):
name = "think-cell-library"
description = "This library consists of several core C++ utilities that we at think-cell Software have developed and consider to be useful."
license = "BSL-1.0 license"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/think-cell/think-cell-library"
topics = ("ranges", "header-only")
package_type = "header-library"
settings = "os", "arch", "compiler", "build_type"
no_copy_source = True

@property
def _min_cppstd(self):
return 20

@property
def _compilers_minimum_version(self):
return {
"apple-clang": "13",
"clang": "7",
"gcc": "12",
"msvc": "191",
"Visual Studio": "15",
}

def layout(self):
basic_layout(self, src_folder="src")

def requirements(self):
self.requires("boost/1.84.0")
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved

def package_id(self):
self.info.clear()

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._min_cppstd)
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version and Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration(
f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support."
)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def build(self):
pass

def package(self):
copy(self, "LICENSE_1_0.txt", self.source_folder, os.path.join(self.package_folder, "licenses"))
copy(
self,
"*.h",
os.path.join(self.source_folder, "tc"),
os.path.join(self.package_folder, "include", "tc"),
)

def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
11 changes: 11 additions & 0 deletions recipes/think-cell-library/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX) # if the project is pure C
# project(test_package LANGUAGES CXX) # if the project uses c++

find_package(think-cell-library REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
# don't link to ${CONAN_LIBS} or CONAN_PKG::package
target_link_libraries(${PROJECT_NAME} PRIVATE think-cell-library::think-cell-library)
# In case the target project need a specific C++ standard
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
27 changes: 27 additions & 0 deletions recipes/think-cell-library/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


# It will become the standard on Conan 2.x
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
147 changes: 147 additions & 0 deletions recipes/think-cell-library/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@

// think-cell public library
//
// Copyright (C) 2016-2018 think-cell Software GmbH
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt

#include "tc/range/meta.h"
#include "tc/range/filter_adaptor.h"
#include "tc/string/format.h"
#include "tc/string/make_c_str.h"

#include <boost/range/adaptors.hpp>

#include <vector>
#include <cstdio>

namespace {

template <typename... Args>
void print(Args&&... args) noexcept {
std::printf("%s", tc::implicit_cast<char const*>(tc::make_c_str<char>(std::forward<Args>(args)...)));
}

//---- Basic ------------------------------------------------------------------------------------------------------------------
void basic () {
std::vector<int> v = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};

tc::for_each(
tc::filter(v, [](const int& n){ return (n%2==0);}),
[&](auto const& n) {
print(tc::as_dec(n), ", ");
}
);
print("\n");
}

//---- Generator Range --------------------------------------------------------------------------------------------------------
namespace {
struct generator_range {
template< typename Func >
void operator()( Func func ) const& {
for(int i=0;i<50;++i) {
func(i);
}
}
};
}

void ex_generator_range () {
tc::for_each( tc::filter( generator_range(), [](int i){ return i%2==0; } ), [](int i) {
print(tc::as_dec(i), ", ");
});
print("\n");
}

//---- Generator Range (with break) -------------------------------------------------------------------------------------------
namespace {
struct generator_range_break {
template< typename Func >
tc::break_or_continue operator()( Func func ) const& {
using namespace tc;
for(int i=0;i<5000;++i) {
if (func(i)==break_) { return break_; }
}
return continue_;
}
};
}

void ex_generator_range_break () {
tc::for_each( tc::filter( generator_range_break(), [](int i){ return i%2==0; } ), [](int i) -> tc::break_or_continue {
print(tc::as_dec(i), ", ");
return (i>=50)? tc::break_ : tc::continue_;
});
print("\n");
}

//---- Stacked filters --------------------------------------------------------------------------------------------------------
void stacked_filters() {
tc::for_each( tc::filter( tc::filter( tc::filter(
generator_range_break(),
[](int i){ return i%2!=0; } ),
[](int i){ return i%3!=0; } ),
[](int i){ return i%5!=0; } )
, [](int i) -> tc::break_or_continue
{
print(tc::as_dec(i), ", ");
return (i>25)? tc::break_ : tc::continue_;
});
print("\n");
}

}

int main() {
print("-- Running Examples ----------\n");

basic();
ex_generator_range();
ex_generator_range_break();
stacked_filters();

using namespace tc;

int av[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
auto v = std::vector<int> (av, av+sizeof(av)/sizeof(int));

//---- filter example with iterators -------------------------------------------

auto r = tc::filter( tc::filter( tc::filter(
v,
[](int i){ return i%2!=0; } ),
[](int i){ return i%3!=0; } ),
[](int i){ return i%5!=0; } );

for (auto it = std::begin(r),
end = std::end(r);
it != end;
++it)
{
print(tc::as_dec(*it), ", ");
}
print("\n");

//---- boost for comparison -----------------------------------------------------

auto br = v | boost::adaptors::filtered([](int i){ return i%2!=0; })
| boost::adaptors::filtered([](int i){ return i%3!=0; })
| boost::adaptors::filtered([](int i){ return i%5!=0; });


for (auto it = std::begin(br),
end = std::end(br);
it != end;
++it)
{
print(tc::as_dec(*it), ", ");
}
print("\n");

print("-- Done ----------\n");
std::fflush(stdout);

return EXIT_SUCCESS;
}
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions recipes/think-cell-library/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
versions:
# Newer versions at the top
"cci.20240426":
folder: all
Loading