Skip to content
Open
Show file tree
Hide file tree
Changes from all 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: 3 additions & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v2

- name: Print env
run: |
Expand Down Expand Up @@ -112,6 +112,7 @@ jobs:
-S . \
-B build \
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-G "${{ matrix.config.generators }}"

- name: Configure C++17
Expand All @@ -123,6 +124,7 @@ jobs:
-S . \
-B build \
-DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-DCMAKE_CXX_STANDARD=17 \
-G "${{ matrix.config.generators }}"

Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@ compile_commands.json
CTestTestfile.cmake
_deps
build/
build*/
build_cpp11/
build_cpp17/
build_gcc/
/.vs
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Ioannis Kaliakatsos
Copyright (c) 2026 Ioannis Kaliakatsos

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
112 changes: 112 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,118 @@ any_of_parallel
none_of_parallel
```

## Functional map usage (fcpp::map)
### map_keys, map_values, map_to, filter, reduce, for_each
```c++
#include "map.h" // instead of <map>

const fcpp::map<std::string, int> ages({
{"jake", 32},
{"mary", 26},
{"david", 40}
});

const auto adults = ages
// keep only key/value pairs matching the predicate
.filtered([](const std::pair<const std::string, int>& element) {
return element.second >= 32;
});

// initials -> fcpp::vector<char>({'d', 'j'})
const auto initials = adults.map_keys<char>([](const std::string& name) {
return name[0];
});

// labels -> fcpp::vector<std::string>({"40 years", "32 years"})
const auto labels = adults.map_values<std::string>([](const int& age) {
return std::to_string(age) + " years";
});

// ages_by_initial -> fcpp::map<char, std::string>({{'d', "40 years"}, {'j', "32 years"}})
const auto ages_by_initial = adults.map_to<char, std::string>([](const std::pair<const std::string, int>& element) {
return std::make_pair(element.first[0], std::to_string(element.second) + " years");
});

// total_age = 72
const auto total_age = adults.reduce(0, [](const int& partial_sum, const std::pair<const std::string, int>& element) {
return partial_sum + element.second;
});

adults.for_each([](const std::pair<const std::string, int>& element) {
std::cout << element.first << " is " << element.second << " years old." << std::endl;
});
```

### all_of, any_of, none_of
```c++
#include "map.h" // instead of <map>

const fcpp::map<std::string, int> ages({
{"jake", 32},
{"mary", 26},
{"david", 40}
});

// returns true
ages.all_of([](const std::pair<const std::string, int>& element) {
return element.second > 20;
});

// returns false
ages.all_of([](const std::pair<const std::string, int>& element) {
return element.second < 35;
});

// returns true
ages.any_of([](const std::pair<const std::string, int>& element) {
return element.second == 40;
});

// returns false
ages.any_of([](const std::pair<const std::string, int>& element) {
return element.second > 50;
});

// returns true
ages.none_of([](const std::pair<const std::string, int>& element) {
return element.second < 18;
});

// returns false
ages.none_of([](const std::pair<const std::string, int>& element) {
return element.second == 26;
});
```

### keys, values, remove, insert
```c++
#include "map.h" // instead of <map>

fcpp::map<std::string, int> ages({
{"jake", 32},
{"mary", 26},
{"david", 40}
});

// names -> fcpp::vector<std::string>({"david", "jake", "mary"})
const auto names = ages.keys();

// years -> fcpp::vector<int>({40, 32, 26})
const auto years = ages.values();

// ages -> fcpp::map<std::string, int>({{"david", 40}, {"jake", 32}})
ages.remove("mary");

// ages -> fcpp::map<std::string, int>({{"anna", 28}, {"david", 40}, {"jake", 32}})
ages.insert("anna", 28);

// without_jake -> fcpp::map<std::string, int>({{"anna", 28}, {"david", 40}})
const auto without_jake = ages.removing("jake");

// with_paul -> fcpp::map<std::string, int>({{"anna", 28}, {"david", 40}, {"jake", 32}, {"paul", 51}})
const auto with_paul = ages.inserting("paul", 51);
```

## Functional set usage (fcpp::set)
### difference, union, intersection (works with fcpp::set and std::set)
```c++
Expand Down
2 changes: 1 addition & 1 deletion include/compatibility.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2023 Ioannis Kaliakatsos
// Copyright (c) 2026 Ioannis Kaliakatsos
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand Down
14 changes: 7 additions & 7 deletions include/export_def.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2023 Ioannis Kaliakatsos
// Copyright (c) 2026 Ioannis Kaliakatsos
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,13 +23,13 @@
#pragma once

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
#ifdef FUNCTIONAL_CPP_EXPORTS
#define FunctionalCppExport __declspec( dllexport )
#ifdef FUNCTIONAL_CPP_EXPORTS
#define FunctionalCppExport __declspec( dllexport )
#else
#define FunctionalCppExport __declspec( dllimport )
#endif
#else
#define FunctionalCppExport __declspec( dllimport )
#endif
#else
#define FunctionalCppExport __attribute__ ((__visibility__("default")))
#define FunctionalCppExport __attribute__ ((__visibility__("default")))
#endif

#include "compatibility.h"
112 changes: 56 additions & 56 deletions include/index_range.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// Copyright (c) 2023 Ioannis Kaliakatsos
// Copyright (c) 2026 Ioannis Kaliakatsos
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -26,60 +26,60 @@
// A struct used for container safe access based on index
struct FunctionalCppExport index_range
{
// Used for returning values of invalid operations
static index_range invalid;

// Create with start index and element count (end index is calculated)
static index_range start_count(int start, int count);

// Create with start and end index (count is calculated)
static index_range start_end(int start, int end);

// The start index of the index range
// example:
// [0] [1] [2] [3] [4] [5] [6]
// 5 3 9 1 8 3 2
// ^ ^
// | |
// start end
//
// start = 2
// end = 4
// count = 3
int start;

// The end index of the index range
// example:
// [0] [1] [2] [3] [4] [5] [6]
// 5 3 9 1 8 3 2
// ^ ^
// | |
// start end
//
// start = 2
// end = 4
// count = 3
int end;

// The total count of the elements in the index range
// example:
// [0] [1] [2] [3] [4] [5] [6]
// 5 3 9 1 8 3 2
// ^ ^
// | |
// start end
//
// start = 2
// end = 4
// count = 3
int count;

// Returns true if it's safe to use its contents
bool is_valid;

bool operator ==(const index_range& rhs) const;
bool operator !=(const index_range& rhs) const;

// Used for returning values of invalid operations
static index_range invalid;
// Create with start index and element count (end index is calculated)
static index_range start_count(int start, int count);
// Create with start and end index (count is calculated)
static index_range start_end(int start, int end);
// The start index of the index range
// example:
// [0] [1] [2] [3] [4] [5] [6]
// 5 3 9 1 8 3 2
// ^ ^
// | |
// start end
//
// start = 2
// end = 4
// count = 3
int start;
// The end index of the index range
// example:
// [0] [1] [2] [3] [4] [5] [6]
// 5 3 9 1 8 3 2
// ^ ^
// | |
// start end
//
// start = 2
// end = 4
// count = 3
int end;
// The total count of the elements in the index range
// example:
// [0] [1] [2] [3] [4] [5] [6]
// 5 3 9 1 8 3 2
// ^ ^
// | |
// start end
//
// start = 2
// end = 4
// count = 3
int count;
// Returns true if it's safe to use its contents
bool is_valid;
bool operator == (const index_range& rhs) const;
bool operator != (const index_range& rhs) const;
private:
index_range(int start, int count);
index_range(int start, int count);
};
Loading
Loading