- CMake
- git
Coming if anybody asks.
Download h.h. Add it to you project.
For example in a folder named include.
Include the header to your .cpp file containing you main function.
#include "include/h.h" // h::hash, h::operator ""_h
// ...
int main(int argc, char** argv) {
switch (h::hash(argv[1])) {
using namespace h::literals;
case "foo"_h:
// ...
case "bar"_h:
// ...
}
}
For examples check out examples.
#include "lib/h.h" // h::hash, h::operator ""_h
#include <print> // std::println
int main(int argc, char** argv) {
using namespace h::literals;
if (argc < 2) return EXIT_FAILURE;
switch (h::hash(argv[1])) {
case "--version"_h:
std::println("com.viraltaco.h v{}", com_viraltaco_h_h);
break;
case "--help"_h:
case "-h"_h:
std::println("--help");
break;
default:
std::println("Invalid input: '{}'", argv[1]);
return EXIT_FAILURE;
}
}See examples/options.cxx
Run the CMake project run-options
#include "lib/h.h" // h::{ hash_t, hash }
#include <vector> // std::vector
template <class T> struct HashMap {
std::vector<h::hash_t> keys;
std::vector<T> values;
constexpr T& operator [](const std::string_view key_str) {
const auto key = h::hash(key_str);
auto idx = 0zu;
for (const auto k: keys) {
if (k == key) { return values[idx]; }
++idx;
}
keys.emplace_back(key);
values.push_back(T{});
return values[idx];
}
};
int main() {
HashMap<int> h{};
h["LMAO"] = 0XDadBeef;
return h["LMAO"] xor 0XDadBeef; // 0
}See examples/hashmap.cxx
Run the CMake project run-hashmap
Run the CMake project run-tests.
Or compile and run ./tests/test.cxx.
This library is provided as-is. Use at your own discretion.
- Fork
- Code (if you add a feature don't forget to write tests for it)
- Test
- Add and commit (if possible: each file individually)
- Push to your remote
- Make a pull request on this repo.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Anthony Capobianco - Initial work - viraltaco_
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see MIT for more information.
- PurpleBooth for
their
README.mdtemplate