├── .clang-format ├── .gitignore ├── 3rdparty └── catch2 │ ├── Catch.cmake │ ├── CatchAddTests.cmake │ ├── ParseAndAddCatchTests.cmake │ └── catch.hpp ├── CMakeLists.txt ├── LICENSE ├── README.md ├── benchmarks ├── CMakeLists.txt ├── filterable │ ├── benchmark_filter_std_containers.cpp │ └── benchmark_filter_std_ranges.cpp ├── functor │ ├── benchmark_map_std_containers.cpp │ └── benchmark_map_std_ranges.cpp └── helpers │ ├── benchmark_main.cpp │ └── expensive.h ├── cmake └── cefal-config.cmake ├── include └── cefal │ ├── cefal │ ├── common.h │ ├── converter.h │ ├── detail │ ├── common_concepts.h │ ├── instantiator.h │ └── std_concepts.h │ ├── everything.h │ ├── filterable.h │ ├── foldable.h │ ├── functor.h │ ├── helpers │ ├── inner_type.h │ ├── nums.h │ ├── std_containers.h │ └── std_ranges.h │ ├── instances │ ├── converter │ │ ├── from_self.h │ │ ├── from_std_containers.h │ │ └── from_std_optional.h │ ├── filterable │ │ ├── from_foldable.h │ │ ├── std_optional.h │ │ ├── std_ranges.h │ │ └── with_functions.h │ ├── foldable │ │ ├── std_containers.h │ │ ├── std_ranges.h │ │ └── with_functions.h │ ├── functor │ │ ├── from_foldable.h │ │ ├── std_optional.h │ │ ├── std_ranges.h │ │ └── with_functions.h │ ├── monad │ │ ├── from_foldable.h │ │ ├── std_optional.h │ │ └── with_functions.h │ └── monoid │ │ ├── basic_types.h │ │ ├── std_containers.h │ │ ├── std_optional.h │ │ └── with_functions.h │ ├── monad.h │ └── monoid.h ├── src └── dummy.cpp └── tests ├── CMakeLists.txt ├── converter ├── test_from_self.cpp ├── test_from_std_containers.cpp └── test_from_std_optional.cpp ├── filterable ├── test_from_foldable.cpp ├── test_std_optional.cpp ├── test_std_ranges.cpp └── test_with_functions.cpp ├── foldable ├── test_std_containers.cpp ├── test_std_ranges.cpp └── test_with_functions.cpp ├── functor ├── test_from_foldable.cpp ├── test_std_optional.cpp ├── test_std_ranges.cpp └── test_with_functions.cpp ├── helpers ├── counter.h ├── ranges_helpers.h ├── test_helpers.h └── test_main.cpp ├── monad ├── test_from_foldable.cpp ├── test_std_optional.cpp └── test_with_functions.cpp └── monoid ├── test_basic_types.cpp ├── test_std_containers.cpp ├── test_std_optional.cpp └── test_with_functions.cpp /.clang-format: -------------------------------------------------------------------------------- 1 | #Requires clang-format >= 10.0.0 2 | 3 | --- 4 | DisableFormat: false 5 | Language: Cpp 6 | Standard: c++20 7 | BasedOnStyle: LLVM 8 | AccessModifierOffset: -4 9 | AlignAfterOpenBracket: Align 10 | AlignConsecutiveAssignments: false 11 | AlignConsecutiveDeclarations: false 12 | AlignConsecutiveMacros: false 13 | AlignEscapedNewlines: Left 14 | AlignOperands: true 15 | AlignTrailingComments: false 16 | AllowAllArgumentsOnNextLine: false 17 | AllowAllConstructorInitializersOnNextLine: true 18 | AllowAllParametersOfDeclarationOnNextLine: false 19 | AllowShortBlocksOnASingleLine: Empty 20 | AllowShortCaseLabelsOnASingleLine: false 21 | AllowShortFunctionsOnASingleLine: InlineOnly 22 | AllowShortIfStatementsOnASingleLine: Never 23 | AllowShortLambdasOnASingleLine: All 24 | AllowShortLoopsOnASingleLine: false 25 | AlwaysBreakAfterReturnType: None 26 | AlwaysBreakBeforeMultilineStrings: false 27 | AlwaysBreakTemplateDeclarations: Yes 28 | BinPackArguments: false 29 | BinPackParameters: true 30 | BreakBeforeBinaryOperators: NonAssignment 31 | BreakBeforeBraces: Attach 32 | BreakBeforeTernaryOperators: true 33 | BreakConstructorInitializers: BeforeComma 34 | BreakInheritanceList: BeforeComma 35 | BreakStringLiterals: true 36 | ColumnLimit: 130 37 | CommentPragmas: "^ *!|^ *:|^ *TODO:|^ *NOTE:|^ *HACK:" 38 | CompactNamespaces: false 39 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 40 | ConstructorInitializerIndentWidth: 4 41 | ContinuationIndentWidth: 4 42 | Cpp11BracedListStyle: true 43 | DerivePointerAlignment: false 44 | FixNamespaceComments: true 45 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH, forever, Q_FOREVER, QBENCHMARK, QBENCHMARK_ONCE ] 46 | IncludeBlocks: Regroup 47 | IncludeCategories: 48 | - Regex: '^"catch2.*' # catch2 headers 49 | Priority: 10 50 | - Regex: '^<.*' # stl/system headers 51 | Priority: 20 52 | - Regex: 'cefal/instances/.*' # Cefal instances 53 | Priority: 5 54 | - Regex: 'cefal/detail/.*' # Cefal other 55 | Priority: 3 56 | - Regex: 'cefal/cefal' # Cefal main 57 | Priority: 2 58 | - Regex: 'cefal/.*' # Cefal other 59 | Priority: 4 60 | - Regex: '.*' # everything else 61 | Priority: 1 62 | IncludeIsMainRegex: '$' 63 | IndentCaseLabels: false 64 | IndentPPDirectives: AfterHash 65 | IndentWidth: 4 66 | IndentWrappedFunctionNames: false 67 | KeepEmptyLinesAtTheStartOfBlocks: false 68 | MacroBlockBegin: '' 69 | MacroBlockEnd: '' 70 | MaxEmptyLinesToKeep: 1 71 | NamespaceIndentation: None 72 | PenaltyBreakAssignment: 100 73 | PenaltyBreakBeforeFirstCallParameter: 300 74 | PenaltyBreakComment: 300 75 | PenaltyBreakFirstLessLess: 50 76 | PenaltyBreakString: 200 77 | PenaltyBreakTemplateDeclaration: 10 78 | PenaltyExcessCharacter: 10 79 | PenaltyReturnTypeOnItsOwnLine: 50 80 | PointerAlignment: Left 81 | ReflowComments: false 82 | SortIncludes: true 83 | SortUsingDeclarations: true 84 | SpaceAfterCStyleCast: false 85 | SpaceAfterLogicalNot: false 86 | SpaceAfterTemplateKeyword: true 87 | SpaceBeforeAssignmentOperators: true 88 | SpaceBeforeCpp11BracedList: false 89 | SpaceBeforeCtorInitializerColon: true 90 | SpaceBeforeInheritanceColon: true 91 | SpaceBeforeParens: ControlStatements 92 | SpaceBeforeRangeBasedForLoopColon: true 93 | SpaceBeforeSquareBrackets: false 94 | SpaceInEmptyBlock: false 95 | SpaceInEmptyParentheses: false 96 | SpacesBeforeTrailingComments: 1 97 | SpacesInAngles: false 98 | SpacesInCStyleCastParentheses: false 99 | SpacesInConditionalStatement: false 100 | SpacesInContainerLiterals: false 101 | SpacesInParentheses: false 102 | SpacesInSquareBrackets: false 103 | TabWidth: 4 104 | UseTab: Never 105 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.user 2 | build/ 3 | build-* 4 | *-build-* 5 | bin 6 | .DS_Store 7 | *.xlsx 8 | *.o 9 | *.so 10 | .vs/ 11 | CMakeSettings.json 12 | .idea/ 13 | -------------------------------------------------------------------------------- /3rdparty/catch2/CatchAddTests.cmake: -------------------------------------------------------------------------------- 1 | # Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2 | # file Copyright.txt or https://cmake.org/licensing for details. 3 | 4 | set(prefix "${TEST_PREFIX}") 5 | set(suffix "${TEST_SUFFIX}") 6 | set(spec ${TEST_SPEC}) 7 | set(extra_args ${TEST_EXTRA_ARGS}) 8 | set(properties ${TEST_PROPERTIES}) 9 | set(script) 10 | set(suite) 11 | set(tests) 12 | 13 | function(add_command NAME) 14 | set(_args "") 15 | foreach(_arg ${ARGN}) 16 | if(_arg MATCHES "[^-./:a-zA-Z0-9_]") 17 | set(_args "${_args} [==[${_arg}]==]") # form a bracket_argument 18 | else() 19 | set(_args "${_args} ${_arg}") 20 | endif() 21 | endforeach() 22 | set(script "${script}${NAME}(${_args})\n" PARENT_SCOPE) 23 | endfunction() 24 | 25 | # Run test executable to get list of available tests 26 | if(NOT EXISTS "${TEST_EXECUTABLE}") 27 | message(FATAL_ERROR 28 | "Specified test executable '${TEST_EXECUTABLE}' does not exist" 29 | ) 30 | endif() 31 | execute_process( 32 | COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-test-names-only 33 | OUTPUT_VARIABLE output 34 | RESULT_VARIABLE result 35 | ) 36 | # Catch --list-test-names-only reports the number of tests, so 0 is... surprising 37 | if(${result} EQUAL 0) 38 | message(WARNING 39 | "Test executable '${TEST_EXECUTABLE}' contains no tests!\n" 40 | ) 41 | elseif(${result} LESS 0) 42 | message(FATAL_ERROR 43 | "Error running test executable '${TEST_EXECUTABLE}':\n" 44 | " Result: ${result}\n" 45 | " Output: ${output}\n" 46 | ) 47 | endif() 48 | 49 | string(REPLACE "\n" ";" output "${output}") 50 | 51 | # Parse output 52 | foreach(line ${output}) 53 | set(test ${line}) 54 | # Escape characters in test case names that would be parsed by Catch2 55 | set(test_name ${test}) 56 | foreach(char , [ ]) 57 | string(REPLACE ${char} "\\${char}" test_name ${test_name}) 58 | endforeach(char) 59 | # ...and add to script 60 | add_command(add_test 61 | "${prefix}${test}${suffix}" 62 | ${TEST_EXECUTOR} 63 | "${TEST_EXECUTABLE}" 64 | "${test_name}" 65 | ${extra_args} 66 | ) 67 | add_command(set_tests_properties 68 | "${prefix}${test}${suffix}" 69 | PROPERTIES 70 | WORKING_DIRECTORY "${TEST_WORKING_DIR}" 71 | ${properties} 72 | ) 73 | list(APPEND tests "${prefix}${test}${suffix}") 74 | endforeach() 75 | 76 | # Create a list of all discovered tests, which users may use to e.g. set 77 | # properties on the tests 78 | add_command(set ${TEST_LIST} ${tests}) 79 | 80 | # Write CTest script 81 | file(WRITE "${CTEST_FILE}" "${script}") 82 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13.0) 2 | 3 | project(cefal VERSION 0.1.0) 4 | 5 | add_library(cefal INTERFACE) 6 | add_library(cefal::cefal ALIAS cefal) 7 | 8 | target_include_directories(cefal INTERFACE 9 | $ 10 | $ 11 | ) 12 | 13 | if(CEFAL_BUILD_DUMMY) 14 | message("-- cefal: Building with dummy unit") 15 | add_executable(cefal_dummy src/dummy.cpp) 16 | target_link_libraries(cefal_dummy PRIVATE cefal::cefal) 17 | target_include_directories(cefal_dummy PRIVATE ${CMAKE_SOURCE_DIR}) 18 | set_target_properties(cefal_dummy PROPERTIES 19 | CXX_STANDARD 20 20 | CXX_STANDARD_REQUIRED ON 21 | CXX_EXTENSIONS OFF 22 | ) 23 | endif() 24 | 25 | include(CMakePackageConfigHelpers) 26 | configure_package_config_file(cmake/cefal-config.cmake 27 | ${CMAKE_BINARY_DIR}/cefal-config.cmake 28 | INSTALL_DESTINATION lib/cmake/cefal 29 | ) 30 | 31 | install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/cefal 32 | DESTINATION include 33 | FILES_MATCHING 34 | PATTERN "*.h" 35 | ) 36 | 37 | install(FILES ${CMAKE_SOURCE_DIR}/include/cefal/cefal 38 | DESTINATION include/cefal 39 | ) 40 | 41 | install(TARGETS cefal 42 | EXPORT cefal-targets 43 | RUNTIME DESTINATION lib 44 | LIBRARY DESTINATION lib 45 | ARCHIVE DESTINATION lib 46 | ) 47 | 48 | install(EXPORT cefal-targets DESTINATION lib/cmake/cefal 49 | NAMESPACE cefal:: 50 | ) 51 | 52 | install(FILES ${CMAKE_BINARY_DIR}/cefal-config.cmake 53 | DESTINATION lib/cmake/cefal 54 | ) 55 | 56 | export(EXPORT cefal-targets FILE ${CMAKE_BINARY_DIR}/cefal-targets.cmake NAMESPACE cefal::) 57 | 58 | if(CEFAL_BUILD_TESTS) 59 | message("-- cefal: Building with tests") 60 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/3rdparty/catch2) 61 | include(Catch) 62 | include(CTest) 63 | enable_testing() 64 | add_subdirectory(tests) 65 | 66 | add_custom_target(with-tests 67 | COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --parallel 8 68 | COMMAND ${CMAKE_COMMAND} -E env CTEST_OUTPUT_ON_FAILURE=1 ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target test 69 | USES_TERMINAL 70 | ) 71 | endif() 72 | 73 | if(CEFAL_BUILD_BENCHMARKS) 74 | message("-- cefal: Building with benchmarks") 75 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/3rdparty/catch2) 76 | include(Catch) 77 | add_subdirectory(benchmarks) 78 | 79 | add_custom_target(with-benchmarks 80 | COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --parallel 8 81 | COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target run-benchmarks 82 | USES_TERMINAL 83 | ) 84 | endif() 85 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2020, Dennis Kormalev 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted 5 | provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, this list of 10 | conditions and the following disclaimer in the documentation and/or other materials provided 11 | with the distribution. 12 | * Neither the name of the copyright holders nor the names of its contributors may be used to 13 | endorse or promote products derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 16 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 17 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 18 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 21 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 22 | OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /benchmarks/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13.0) 2 | 3 | macro(cefal_benchmark dir target) 4 | set(target_name benchmark_${dir}_${target}) 5 | add_executable(${target_name} ${dir}/benchmark_${target}.cpp helpers/benchmark_main.cpp) 6 | set_target_properties(${target_name} PROPERTIES 7 | CXX_STANDARD 20 8 | CXX_STANDARD_REQUIRED ON 9 | CXX_EXTENSIONS OFF) 10 | target_compile_options(${target_name} PRIVATE -Wno-unused-variable) 11 | target_include_directories(${target_name} PRIVATE ${CMAKE_SOURCE_DIR}/3rdparty ${CMAKE_SOURCE_DIR}/benchmarks/helpers) 12 | target_link_libraries(${target_name} cefal::cefal) 13 | 14 | add_custom_target(run-${target_name} 15 | COMMAND ${CMAKE_BINARY_DIR}/benchmarks/${target_name} 16 | USES_TERMINAL) 17 | add_dependencies(run-benchmarks run-${target_name}) 18 | endmacro() 19 | 20 | add_custom_target(run-benchmarks) 21 | 22 | cefal_benchmark(functor map_std_containers) 23 | cefal_benchmark(functor map_std_ranges) 24 | 25 | cefal_benchmark(filterable filter_std_containers) 26 | cefal_benchmark(filterable filter_std_ranges) 27 | -------------------------------------------------------------------------------- /benchmarks/helpers/benchmark_main.cpp: -------------------------------------------------------------------------------- 1 | #define CATCH_CONFIG_ENABLE_BENCHMARKING 2 | #define CATCH_CONFIG_CONSOLE_WIDTH 90 3 | #define CATCH_CONFIG_MAIN 4 | #include "catch2/catch.hpp" 5 | -------------------------------------------------------------------------------- /benchmarks/helpers/expensive.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020, Dennis Kormalev 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, are permitted 5 | * provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, this list of 8 | * conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, this list of 10 | * conditions and the following disclaimer in the documentation and/or other materials provided 11 | * with the distribution. 12 | * * Neither the name of the copyright holders nor the names of its contributors may be used to 13 | * endorse or promote products derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 17 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 21 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 22 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | * 24 | */ 25 | 26 | #pragma once 27 | 28 | #include 29 | #include 30 | 31 | template 32 | struct Expensive { 33 | Expensive(T x = T()) : value(std::move(x)), payload(new char[102400]) {} 34 | Expensive(T x, char* payload) : value(std::move(x)), payload(payload) {} 35 | Expensive(const Expensive& other) { 36 | payload = new char[102400]; 37 | value = other.value; 38 | } 39 | Expensive(Expensive&& other) { 40 | payload = other.payload; 41 | value = std::move(other.value); 42 | other.payload = nullptr; 43 | } 44 | Expensive& operator=(const Expensive& other) { 45 | delete[] payload; 46 | payload = new char[102400]; 47 | value = other.value; 48 | return *this; 49 | } 50 | Expensive& operator=(Expensive&& other) { 51 | std::swap(payload, other.payload); 52 | value = std::move(other.value); 53 | return *this; 54 | } 55 | ~Expensive() { delete[] payload; } 56 | 57 | operator T() const { return value; } 58 | 59 | template 60 | bool operator%(U&& other) const { 61 | return value % other; 62 | } 63 | 64 | template 65 | Expensive> operator+(U&& other) const& { 66 | return Expensive>(value + other); 67 | } 68 | 69 | template 70 | Expensive> operator+(U&& other) && { 71 | auto result = Expensive>(value + other, payload); 72 | payload = nullptr; 73 | return result; 74 | } 75 | 76 | Expensive& operator+=(T other) { 77 | value += other; 78 | return *this; 79 | } 80 | 81 | auto operator<=>(const Expensive& other) const { return value <=> other.value; } 82 | bool operator==(const Expensive& other) const { return std::abs(value - other.value) < 0.0001; } 83 | 84 | T value = T(); 85 | char* payload = nullptr; 86 | }; 87 | 88 | namespace std { 89 | template 90 | struct hash> { 91 | size_t operator()(const Expensive& x) const { return std::hash()(x.value); } 92 | }; 93 | } // namespace std 94 | -------------------------------------------------------------------------------- /cmake/cefal-config.cmake: -------------------------------------------------------------------------------- 1 | include(CMakeFindDependencyMacro) 2 | 3 | if(NOT TARGET cefal::cefal) 4 | include("${CMAKE_CURRENT_LIST_DIR}/cefal-targets.cmake") 5 | endif() 6 | -------------------------------------------------------------------------------- /include/cefal/cefal: -------------------------------------------------------------------------------- 1 | /* Copyright 2020, Dennis Kormalev 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, are permitted 5 | * provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, this list of 8 | * conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, this list of 10 | * conditions and the following disclaimer in the documentation and/or other materials provided 11 | * with the distribution. 12 | * * Neither the name of the copyright holders nor the names of its contributors may be used to 13 | * endorse or promote products derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 17 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 21 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 22 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | * 24 | */ 25 | 26 | #include "cefal/converter.h" 27 | #include "cefal/common.h" 28 | #include "cefal/foldable.h" 29 | #include "cefal/functor.h" 30 | #include "cefal/monad.h" 31 | #include "cefal/monoid.h" 32 | -------------------------------------------------------------------------------- /include/cefal/common.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020, Dennis Kormalev 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, are permitted 5 | * provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, this list of 8 | * conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, this list of 10 | * conditions and the following disclaimer in the documentation and/or other materials provided 11 | * with the distribution. 12 | * * Neither the name of the copyright holders nor the names of its contributors may be used to 13 | * endorse or promote products derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 17 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 21 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 22 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | * 24 | */ 25 | 26 | #pragma once 27 | 28 | #include "cefal/detail/common_concepts.h" 29 | 30 | #include "cefal/helpers/inner_type.h" 31 | #include "cefal/helpers/nums.h" 32 | 33 | #include 34 | 35 | namespace cefal { 36 | namespace ops { 37 | namespace detail { 38 | template 39 | inline auto operator|(Left&& left, Op&& op) { 40 | return std::forward(op)(std::forward(left)); 41 | } 42 | } // namespace detail 43 | template 44 | inline auto operator|(Left&& left, Op&& op) { 45 | return std::forward(op)(std::forward(left)); 46 | } 47 | } // namespace ops 48 | } // namespace cefal 49 | -------------------------------------------------------------------------------- /include/cefal/converter.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020, Dennis Kormalev 2 | * All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without modification, are permitted 5 | * provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, this list of 8 | * conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright notice, this list of 10 | * conditions and the following disclaimer in the documentation and/or other materials provided 11 | * with the distribution. 12 | * * Neither the name of the copyright holders nor the names of its contributors may be used to 13 | * endorse or promote products derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 17 | * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 21 | * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 22 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | * 24 | */ 25 | 26 | #pragma once 27 | 28 | #include "cefal/detail/instantiator.h" 29 | 30 | #include "cefal/common.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | namespace cefal { 37 | namespace instances { 38 | template 39 | struct Converter; 40 | } // namespace instances 41 | 42 | namespace concepts { 43 | // clang-format off 44 | template 45 | concept CanConvert = requires(T x) { 46 | { instances::Converter::convert(x) } -> std::same_as; 47 | { instances::Converter::convert(std::move(x)) } -> std::same_as; 48 | }; 49 | // clang-format on 50 | } // namespace concepts 51 | 52 | namespace ops { 53 | namespace detail { 54 | template