{"action":"opened","issue":{"url":"https://api.github.com/repos/bassosimone/mkok-experimental-tor/issues/10","repository_url":"https://api.github.com/repos/bassosimone/mkok-experimental-tor","labels_url":"https://api.github.com/repos/bassosimone/mkok-experimental-tor/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/bassosimone/mkok-experimental-tor/issues/10/comments","events_url":"https://api.github.com/repos/bassosimone/mkok-experimental-tor/issues/10/events","html_url":"https://github.com/bassosimone/mkok-experimental-tor/issues/10","id":132945488,"number":10,"title":"Distinguish between errors without using numbers","user":{"login":"bassosimone","id":337298,"avatar_url":"https://avatars.githubusercontent.com/u/337298?v=3","gravatar_id":"","url":"https://api.github.com/users/bassosimone","html_url":"https://github.com/bassosimone","followers_url":"https://api.github.com/users/bassosimone/followers","following_url":"https://api.github.com/users/bassosimone/following{/other_user}","gists_url":"https://api.github.com/users/bassosimone/gists{/gist_id}","starred_url":"https://api.github.com/users/bassosimone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bassosimone/subscriptions","organizations_url":"https://api.github.com/users/bassosimone/orgs","repos_url":"https://api.github.com/users/bassosimone/repos","events_url":"https://api.github.com/users/bassosimone/events{/privacy}","received_events_url":"https://api.github.com/users/bassosimone/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-11T11:15:35Z","updated_at":"2016-02-11T11:15:35Z","closed_at":null,"body":"It is worth investigating this possibility (cc: @DavideAllavena):\r\n\r\n```C++\r\n// error.hpp\r\n#include <typeinfo>\r\n#include <typeindex>\r\n\r\nclass Error {\r\n  public:\r\n    std::type_index type_index() {\r\n        return std::type_index(typeid(*this));\r\n    }\r\n\r\n    bool operator==(Error &other) {\r\n        return type_index() == other.type_index();\r\n    }\r\n\r\n    bool operator!=(Error &other) {\r\n        return type_index() != other.type_index();\r\n    }\r\n\r\n    Error() {}\r\n    virtual ~Error();\r\n};\r\n\r\n#define MK_DECLARE_ERROR(name)                                                 \\\r\n    class name : public Error {                                                \\\r\n      public:                                                                  \\\r\n        ~name() override;                                                      \\\r\n    };\r\n\r\n#define MK_IMPLEMENT_ERROR(name)                                               \\\r\n    name::~name() {}\r\n\r\nMK_DECLARE_ERROR(SpecificError)\r\n```\r\n\r\n```C++\r\n// main.cpp\r\n#include \"error.hpp\"\r\n#include <iostream>\r\n\r\nError::~Error() {}\r\nMK_IMPLEMENT_ERROR(SpecificError)\r\n\r\nint main() {\r\n    Error base;\r\n    Error another;\r\n    SpecificError child;\r\n    std::cout << (bool) (base == another) << \"\\n\";\r\n    std::cout << (bool) (base == child) << \"\\n\";\r\n    std::cout << (bool) (base != another) << \"\\n\";\r\n    std::cout << (bool) (base != child) << \"\\n\";\r\n}\r\n```\r\n\r\n```bash\r\n$ clang++ -Weverything -Wall -std=c++11 main.cpp \r\nIn file included from error.cpp:1:\r\n./error.hpp:31:1: warning: 'override' keyword is incompatible with C++98 [-Wc++98-compat]\r\nMK_DECLARE_ERROR(SpecificError)\r\n^\r\n./error.hpp:25:17: note: expanded from macro 'MK_DECLARE_ERROR'\r\n        ~name() override;                                                      \\\r\n                ^\r\nerror.cpp:11:18: warning: use of old-style cast [-Wold-style-cast]\r\n    std::cout << (bool) (base == another) << \"\\n\";\r\n                 ^      ~~~~~~~~~~~~~~~~~\r\nerror.cpp:12:18: warning: use of old-style cast [-Wold-style-cast]\r\n    std::cout << (bool) (base == child) << \"\\n\";\r\n                 ^      ~~~~~~~~~~~~~~~\r\nerror.cpp:13:18: warning: use of old-style cast [-Wold-style-cast]\r\n    std::cout << (bool) (base != another) << \"\\n\";\r\n                 ^      ~~~~~~~~~~~~~~~~~\r\nerror.cpp:14:18: warning: use of old-style cast [-Wold-style-cast]\r\n    std::cout << (bool) (base != child) << \"\\n\";\r\n                 ^      ~~~~~~~~~~~~~~~\r\n5 warnings generated.\r\n$ ./a.out \r\n1\r\n0\r\n0\r\n1\r\n```"}}