{"action":"created","issue":{"url":"https://api.github.com/repos/jimporter/mettle/issues/13","labels_url":"https://api.github.com/repos/jimporter/mettle/issues/13/labels{/name}","comments_url":"https://api.github.com/repos/jimporter/mettle/issues/13/comments","events_url":"https://api.github.com/repos/jimporter/mettle/issues/13/events","html_url":"https://github.com/jimporter/mettle/issues/13","id":106881572,"number":13,"title":"near_to( ) takes literal numbers but not variables","user":{"login":"darenw","id":4267721,"avatar_url":"https://avatars.githubusercontent.com/u/4267721?v=3","gravatar_id":"","url":"https://api.github.com/users/darenw","html_url":"https://github.com/darenw","followers_url":"https://api.github.com/users/darenw/followers","following_url":"https://api.github.com/users/darenw/following{/other_user}","gists_url":"https://api.github.com/users/darenw/gists{/gist_id}","starred_url":"https://api.github.com/users/darenw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/darenw/subscriptions","organizations_url":"https://api.github.com/users/darenw/orgs","repos_url":"https://api.github.com/users/darenw/repos","events_url":"https://api.github.com/users/darenw/events{/privacy}","received_events_url":"https://api.github.com/users/darenw/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-16T23:04:14Z","updated_at":"2015-09-17T06:50:02Z","closed_at":"2015-09-17T06:50:02Z","body":"Is this a bug or am I doing this wrong?   Many of the resulting values in our tests will be 1/sqrt(2) or similar constants, for which I have defined constants.  Trouble, near_to_abs() works fine only with explicit number like 123.45, not variables of const double type (or just double).  I'm working in a subsuite within a suite, unsure if it's something to do with [=] captures.  \r\n\r\nIt doesn't matter if I use near_to( ) or near_to_abs( ).\r\n\r\nI tried moving the \"sq\" variable definition to inside the suite, but the result is the same. I've tried defining other variable names, toying with where they are and how to capture them in the lambdas, but I have not yet guessed the right combination.\r\n\r\n\r\nSOURCE CODE   ut.buggy-array.cpp\r\n\r\n```\r\n// How to check an array using constants from outside the test lambda?\r\n//\r\n//     g++ -g -o ut  ut.buggy-array.cpp  --std=c++14\r\n\r\n#include <mettle.hpp>\r\n#if 0\r\nusing mettle::near_to;\r\nusing mettle::near_to_abs;\r\nusing mettle::equal_to;\r\nusing mettle::array;\r\n#else\r\nusing namespace mettle;\r\n#endif\r\n\r\n// A heavily used constant, expected in many results of tests\r\nconst double sq = 1.0 / sqrt(2.0);\r\n\r\nmettle::suite<>  TestThis(\"xxx\",  [=](auto &_)   {\r\n\r\n    const double ep = 1E-6;\r\n    \r\n    _.subsuite(\"QQQ\",  [=](auto &_)   {\r\n        \r\n        _.test(\"X90\",  [=]()   {\r\n            double Q[4];\r\n        \r\n            // Function under test ... faked for bug finding\r\n            Q[0]=Q[1]=Q[2]=Q[3] = 1.6;\r\n            \r\n/*OK */     expect(Q, array( near_to(6.6,2.2), near_to(6.6,2.2), near_to(6.6,2.2), near_to(6.6,2.2) ));\r\n/*BAD*/     expect(Q, array( near_to(sq,2.2), near_to(sq,2.2), near_to(sq,2.2), near_to(sq,2.2) ));\r\n/*OK */     expect(Q, array( near_to(6.6,ep), near_to(6.6,ep), near_to(6.6,ep), near_to(6.6,ep) ));\r\n/*BAD*/     expect(Q, array( near_to(sq,ep), near_to_abs(sq,ep), near_to_abs(sq,ep), near_to_abs(sq,ep) ));\r\n        }); \r\n        \r\n    }); // subsuite\r\n}); // suite\r\n```\r\n\r\nCompiling results in:\r\n```\r\n> g++ -g  -o ut    ut.buggy-array.cpp  --std=c++14                                                                                 \r\nut.buggy-array.cpp: In lambda function:\r\nut.buggy-array.cpp:32:44: error: no matching function for call to 'near_to(const double&, double)'\r\n /*BAD*/     expect(Q, array( near_to(sq,2.2), near_to(sq,2.2), near_to(sq,2.2), near_to(sq,2.2) ));\r\n                                            ^\r\nIn file included from /usr/include/mettle/matchers.hpp:7:0,\r\n                 from /usr/include/mettle.hpp:5,\r\n                 from ut.buggy-array.cpp:5:\r\n/usr/include/mettle/matchers/arithmetic.hpp:14:6: note: candidate: template<class T> auto mettle::near_to(T&&, const T&)\r\n auto near_to(T &&expected, const T &epsilon) {\r\n      ^\r\n/usr/include/mettle/matchers/arithmetic.hpp:14:6: note:   template argument deduction/substitution failed:\r\nut.buggy-array.cpp:32:44: note:   deduced conflicting types for parameter 'const T' ('const double&' and 'double')\r\n /*BAD*/     expect(Q, array( near_to(sq,2.2), near_to(sq,2.2), near_to(sq,2.2), near_to(sq,2.2) ));\r\n                                            ^\r\nIn file included from /usr/include/mettle/matchers.hpp:7:0,\r\n                 from /usr/include/mettle.hpp:5,\r\n                 from ut.buggy-array.cpp:5:\r\n/usr/include/mettle/matchers/arithmetic.hpp:27:13: note: candidate: template<class T> typename std::enable_if<(! std::numeric_limits<_Tp>::is_integer), decltype (mettle::near_to(declval<T>(), declval<T>()))>::type mettle::near_to(T&&)\r\n inline auto near_to(T &&expected) -> typename std::enable_if<\r\n             ^\r\n/usr/include/mettle/matchers/arithmetic.hpp:27:13: note:   template argument deduction/substitution failed:\r\nut.buggy-array.cpp:32:44: note:   candidate expects 1 argument, 2 provided\r\n /*BAD*/     expect(Q, array( near_to(sq,2.2), near_to(sq,2.2), near_to(sq,2.2), near_to(sq,2.2) ));\r\n                                            ^\r\n```\r\n(This is just the first of several. Errors come four at a time per /*BAD*/ line)\r\n"},"comment":{"url":"https://api.github.com/repos/jimporter/mettle/issues/comments/140985893","html_url":"https://github.com/jimporter/mettle/issues/13#issuecomment-140985893","issue_url":"https://api.github.com/repos/jimporter/mettle/issues/13","id":140985893,"user":{"login":"jimporter","id":826865,"avatar_url":"https://avatars.githubusercontent.com/u/826865?v=3","gravatar_id":"","url":"https://api.github.com/users/jimporter","html_url":"https://github.com/jimporter","followers_url":"https://api.github.com/users/jimporter/followers","following_url":"https://api.github.com/users/jimporter/following{/other_user}","gists_url":"https://api.github.com/users/jimporter/gists{/gist_id}","starred_url":"https://api.github.com/users/jimporter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jimporter/subscriptions","organizations_url":"https://api.github.com/users/jimporter/orgs","repos_url":"https://api.github.com/users/jimporter/repos","events_url":"https://api.github.com/users/jimporter/events{/privacy}","received_events_url":"https://api.github.com/users/jimporter/received_events","type":"User","site_admin":false},"created_at":"2015-09-17T06:50:02Z","updated_at":"2015-09-17T06:50:02Z","body":"That should do it, plus some tests so it can't regress. Thanks again!"}}