Skip to content

Instantly share code, notes, and snippets.

@PhDP
Last active June 18, 2017 19:34
Show Gist options
  • Save PhDP/8add2f5d55484b167859714b6b14bd80 to your computer and use it in GitHub Desktop.
Save PhDP/8add2f5d55484b167859714b6b14bd80 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <map>
#include <unordered_map>
template<typename Key, typename Value>
using stdmap = std::map<Key, Value>;
template<typename Key, typename Value>
using stdumap = std::unordered_map<Key, Value>;
template<typename Key,
typename Real = double,
template<typename, typename...> class MapType = stdmap>
using fuzzy_set = MapType<Key, Real>;
template<typename FuzzySet>
auto fuzzy_mem(FuzzySet const& fz, typename FuzzySet::key_type key) -> typename FuzzySet::mapped_type {
auto const it = fz.find(key);
return it != fz.end()? it->second : 0;
}
auto main() -> int {
auto const fs = fuzzy_set<int, double>{{4, 0.6}, {6, 0.9}, {1, 0.1}, {3, 0.8}};
std::cout << fuzzy_mem(fs, 4) << '\n' << fuzzy_mem(fs, -1) << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment