Skip to content

Instantly share code, notes, and snippets.

@goyusia
Created October 23, 2015 16:12
Show Gist options
  • Select an option

  • Save goyusia/58a075f6cd4590bbac99 to your computer and use it in GitHub Desktop.

Select an option

Save goyusia/58a075f6cd4590bbac99 to your computer and use it in GitHub Desktop.
new history teaching
main:
make current; \
make dystopia
current: new_history_teaching.cpp
rm -rf a.out
clang++ $^ -W -Wall
./a.out
dystopia: new_history_teaching.cpp
rm -rf a.out
clang++ $^ -W -Wall -DNEW_HISTORY_TEACHING
./a.out
clean:
rm -rf a.out *.o
/*
Usage
$ make current
new_history_teaching.cpp:23:9: error: no viable overloaded operator[] for type 'const history_t' (aka 'const map<year_t, event_t>')
history[1972] = "nothing";
...
(compile error)
$ make dystopia
what happend in 1972 : nothing
*/
#include <map>
#include <string>
#include <cstdio>
#if NEW_HISTORY_TEACHING
#define const
#endif
typedef int year_t;
typedef std::string event_t;
typedef std::map<year_t, event_t> history_t;
const history_t create_original_history()
{
history_t h;
h[1972] = "유신";
return h;
}
int main()
{
const history_t history = create_original_history();
history[1972] = "nothing";
printf("what happend in 1972 : %s\n", history[1972].data());
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment