{"action":"created","issue":{"url":"https://api.github.com/repos/hostilefork/rencpp/issues/24","labels_url":"https://api.github.com/repos/hostilefork/rencpp/issues/24/labels{/name}","comments_url":"https://api.github.com/repos/hostilefork/rencpp/issues/24/comments","events_url":"https://api.github.com/repos/hostilefork/rencpp/issues/24/events","html_url":"https://github.com/hostilefork/rencpp/issues/24","id":53052161,"number":24,"title":"Review if the non-explicit Logic constructor can be narrowed to boolean","user":{"login":"hostilefork","id":20440,"avatar_url":"https://avatars.githubusercontent.com/u/20440?v=3","gravatar_id":"","url":"https://api.github.com/users/hostilefork","html_url":"https://github.com/hostilefork","followers_url":"https://api.github.com/users/hostilefork/followers","following_url":"https://api.github.com/users/hostilefork/following{/other_user}","gists_url":"https://api.github.com/users/hostilefork/gists{/gist_id}","starred_url":"https://api.github.com/users/hostilefork/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hostilefork/subscriptions","organizations_url":"https://api.github.com/users/hostilefork/orgs","repos_url":"https://api.github.com/users/hostilefork/repos","events_url":"https://api.github.com/users/hostilefork/events{/privacy}","received_events_url":"https://api.github.com/users/hostilefork/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/hostilefork/rencpp/labels/type.review","name":"type.review","color":"FF8C00"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2014-12-29T16:27:25Z","updated_at":"2015-03-30T08:19:47Z","closed_at":"2015-03-30T03:38:37Z","body":"I hit a bug from the boolean conversion of a `char *` string literal counting as a valid implicit `ren::Logic`.  I started thinking about how to write a constructor which would implicitly only accept a real bool, but would explicitly convert anything that could be a bool.  I tried something along these lines:\r\n\r\n    template <\r\n        typename T,\r\n        typename = typename std::enable_if<\r\n            std::is_same<bool, T>::value, T\r\n        >::type\r\n    >\r\n    Logic (T const & b) :\r\n        Value (b)\r\n    {\r\n    }\r\n\r\n    // If you're super sure, use this explicit constructor\r\n    template <\r\n        typename T,\r\n        typename = typename std::enable_if<\r\n            not std::is_same<bool, T>::value, T\r\n        >::type\r\n    >\r\n    explicit Logic(T const & b) :\r\n        Value (b)\r\n    {\r\n    }\r\n\r\nIt didn't work.  Don't want to get sidetracked with an SO question formalism ATM, but recording the issue here... perhaps @Morwenn has tried something like this before?  Looking for:\r\n\r\n    void foo(Logic const & val) {\r\n        // ...\r\n    }\r\n\r\n    foo(true); // should work\r\n    foo(\"hello\"); // shouldn't work\r\n    foo(15); // shouldn't work\r\n\r\n    foo(Logic {true}); // should work\r\n    foo(Logic {\"hello\"}); // should work\r\n    foo(Logic {15}); // should work"},"comment":{"url":"https://api.github.com/repos/hostilefork/rencpp/issues/comments/87588031","html_url":"https://github.com/hostilefork/rencpp/issues/24#issuecomment-87588031","issue_url":"https://api.github.com/repos/hostilefork/rencpp/issues/24","id":87588031,"user":{"login":"Morwenn","id":1164683,"avatar_url":"https://avatars.githubusercontent.com/u/1164683?v=3","gravatar_id":"","url":"https://api.github.com/users/Morwenn","html_url":"https://github.com/Morwenn","followers_url":"https://api.github.com/users/Morwenn/followers","following_url":"https://api.github.com/users/Morwenn/following{/other_user}","gists_url":"https://api.github.com/users/Morwenn/gists{/gist_id}","starred_url":"https://api.github.com/users/Morwenn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Morwenn/subscriptions","organizations_url":"https://api.github.com/users/Morwenn/orgs","repos_url":"https://api.github.com/users/Morwenn/repos","events_url":"https://api.github.com/users/Morwenn/events{/privacy}","received_events_url":"https://api.github.com/users/Morwenn/received_events","type":"User","site_admin":false},"created_at":"2015-03-30T08:19:47Z","updated_at":"2015-03-30T08:19:47Z","body":"It's great to see that you finally found a solution with SFINAE instead of esoteric tricks. While `std::is_convertible` is not pretty, it is actually exactly the tool we need and documents well the issue by itself. Congratulations :)"}}