This commit is contained in:
Ingy döt Net 2013-06-05 21:47:54 +00:00
parent 1f1ad49427
commit 6f050a029e
2496 changed files with 37609 additions and 3031 deletions

View file

@ -0,0 +1,18 @@
( new$hash:?myhash
& (myhash..insert)$(title."Some title")
& (myhash..insert)$(formula.a+b+x^7)
& (myhash..insert)$(fruit.apples oranges kiwis)
& (myhash..insert)$(meat.)
& (myhash..insert)$(fruit.melons bananas)
& (myhash..remove)$formula
& (myhash..insert)$(formula.x^2+y^2)
& (myhash..forall)
$ (
= key value
. whl
' ( !arg:(?key.?value) ?arg
& put$("key:" !key "\nvalue:" !value \n)
)
& put$\n
)
);

View file

@ -1,12 +1,33 @@
std::map<std::string, int> myDict;
myDict["hello"] = 1;
myDict["world"] = 2;
myDict["!"] = 3;
#include <map>
#include <iostream>
#include <algorithm>
#include <vector>
// iterating over key-value pairs:
for (std::map<std::string, int>::iterator it = myDict.begin(); it != myDict.end(); it++) {
// the thing pointed to by the iterator is a pair<std::string, int>
std::string key = it->first;
int value = it->second;
std::cout << "key = " << key << ", value = " << value << std::endl;
int main() {
using MyDict = std::map<std::string, int>;
MyDict dict = {
{"One", 1},
{"Two", 2},
{"Three", 7}
};
dict["Three"] = 3;
std::cout << "One: " << dict["One"] << std::endl;
// Make vector of the keys from our map
std::vector<std::string> keys;
std::transform(dict.begin(), dict.end(), std::back_inserter(keys),
[](MyDict::value_type& kv) { return kv.first; });
std::cout << "Keys: " << std::endl;
for(auto& key: keys) std::cout << " " << key << std::endl;
std::cout << "Key/Value pairs: " << std::endl;
for(auto& kv: dict) {
std::cout << " " << kv.first << ": " << kv.second << std::endl;
}
return 0;
}

View file

@ -1,21 +1,12 @@
#include <map>
#include <algorithm>
#include <iostream>
#include <string>
std::map<std::string, int> myDict;
myDict["hello"] = 1;
myDict["world"] = 2;
myDict["!"] = 3;
using namespace std;
int main()
{
map<string, int> myDict;
myDict["hello"] = 1;
myDict["world"] = 2;
myDict["!"] = 3;
for_each(myDict.begin(), myDict.end(),
[](const pair<string,int>& p)
{
cout << "key = " << p.first << ", value = " << p.second << endl;
});
return 0;
// iterating over key-value pairs:
for (std::map<std::string, int>::iterator it = myDict.begin(); it != myDict.end(); it++) {
// the thing pointed to by the iterator is a pair<std::string, int>
std::string key = it->first;
int value = it->second;
std::cout << "key = " << key << ", value = " << value << std::endl;
}