Skip to content

Repository files navigation

beman.copyable_function: A Beman Library Implementation of copyable_function

Library StatusContinuous Integration TestsLint Check (pre-commit)CoverageStandard TargetCompiler Explorer Example

beman.copyable_function is a type-erased function wrapper that can represent any copyable callable matching the function signature R(Args...). The library conforms to the The Beman Standard.

Implements: copyable_function (P2548)

Status: Under development and not yet ready for production use.

License

beman.copyable_function is licensed under the Apache License v2.0 with LLVM Exceptions.

Usage

The following code snippet illustrates copyable_function:

#include<beman/copyable_function/copyable_function.hpp>// a Callable objectstructCallable {
intoperator()() { return42; }
intoperator()() constnoexcept { return43; }
};
intmain()
{
beman::copyable_function<int()> f(Callable{});
int x = f();
return0;
}

Full runnable examples can be found in examples/.

Dependencies

Build Environment

This project requires at least the following to build:

  • A C++ compiler that conforms to the C++17 standard or greater
  • CMake 3.30 or later
  • (Test Only) GoogleTest

You can disable building tests by setting CMake option BEMAN_COPYABLE_FUNCTION_BUILD_TESTS to OFF when configuring the project.

You can disable building examples by setting CMake option BEMAN_COPYABLE_FUNCTION_BUILD_EXAMPLES to OFF when configuring the project.

Supported Platforms

CompilerVersionC++ StandardsStandard Library
GCC16-13C++26, C++23libstdc++
GCC12C++23libstdc++
Clang22-19C++26, C++23libstdc++, libc++
Clang18C++26, C++23libc++
Clang18C++23libstdc++
Clang17C++26, C++23libc++
AppleClanglatestC++26, C++23libc++
MSVClatestC++23MSVC STL

Development

See the Contributing Guidelines.

Integrate beman.copyable_function into your project

Build

You can build copyable_function using a CMake workflow preset:

cmake --workflow --preset gcc-release

To list available workflow presets, you can invoke:

cmake --list-presets=workflow

For details on building beman.copyable_function without using a CMake preset, refer to the Contributing Guidelines.

Installation

Vcpkg

The preferred way to install copyable_function is via vcpkg. To do so, after installing vcpkg itself, you need to add support for the Beman project's vcpkg registry by configuring a vcpkg-configuration.json file (which copyable_function provides).

Then, simply run vcpkg install beman-copyable-function.

Manual

To install beman.copyable_function globally after building with the gcc-release preset, you can run:

sudo cmake --install build/gcc-release

Alternatively, to install to a prefix, for example /opt/beman, you can run:

sudo cmake --install build/gcc-release --prefix /opt/beman

This will generate the following directory structure:

/opt/beman
├── include
│ └── beman
│ └── copyable_function
│ ├── copyable_function.hpp
│ └── ...
└── lib
└── cmake
└── beman.copyable_function
├── beman.copyable_function-config-version.cmake
├── beman.copyable_function-config.cmake
└── beman.copyable_function-targets.cmake

CMake Configuration

If you installed beman.copyable_function to a prefix, you can specify that prefix to your CMake project using CMAKE_PREFIX_PATH; for example, -DCMAKE_PREFIX_PATH=/opt/beman.

You need to bring in the beman.copyable_function package to define the beman::copyable_function CMake target:

find_package(beman.copyable_functionREQUIRED)

You will then need to add beman::copyable_function to the link libraries of any libraries or executables that include beman.copyable_function headers.

target_link_libraries(yourlibPUBLICbeman::copyable_function)

Using beman.copyable_function

To use beman.copyable_function in your C++ project, include an appropriate beman.copyable_function header from your source code.

#include<beman/copyable_function/copyable_function.hpp>

Contributing

Please do! You encourage you to checkout our contributor's guide. Issues and pull requests are appreciated.

About

No description, website, or topics provided.

Resources

Contributing

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages

Generated from bemanproject/exemplar