{"id":20788939,"url":"https://github.com/bfgroup/duck_invoke","last_synced_at":"2025-10-22T03:01:32.561Z","repository":{"id":104906742,"uuid":"276142755","full_name":"bfgroup/duck_invoke","owner":"bfgroup","description":"A simple to use, single header, tag_invoke utility for C++11.","archived":false,"fork":false,"pushed_at":"2022-11-27T03:11:30.000Z","size":7771,"stargazers_count":16,"open_issues_count":1,"forks_count":1,"subscribers_count":5,"default_branch":"develop","last_synced_at":"2025-05-05T19:04:04.959Z","etag":null,"topics":["cpp","cpp11","cpp14","cpp17","cpp20","header-only"],"latest_commit_sha":null,"homepage":"https://bfgroup.github.io/duck_invoke/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bfgroup.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["grafikrobot"]}},"created_at":"2020-06-30T15:44:55.000Z","updated_at":"2024-09-04T08:26:33.000Z","dependencies_parsed_at":"2023-04-30T20:32:30.489Z","dependency_job_id":null,"html_url":"https://github.com/bfgroup/duck_invoke","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/bfgroup/duck_invoke","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfgroup%2Fduck_invoke","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfgroup%2Fduck_invoke/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfgroup%2Fduck_invoke/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfgroup%2Fduck_invoke/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bfgroup","download_url":"https://codeload.github.com/bfgroup/duck_invoke/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfgroup%2Fduck_invoke/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269300933,"owners_count":24394066,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-07T02:00:09.698Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","cpp11","cpp14","cpp17","cpp20","header-only"],"created_at":"2024-11-17T15:18:20.523Z","updated_at":"2025-10-22T03:01:32.418Z","avatar_url":"https://github.com/bfgroup.png","language":"C++","readme":"= Duck Invoke\n\n// tag::intro[]\n\n[.tagline]\nA simple to use, single header, `tag_invoke` utility for C++11.\n\n[horizontal.shields]\nObtain:: image:https://img.shields.io/github/downloads/bfgroup/duck_invoke/total.svg?label=GitHub[GitHub All Releases, link=\"https://github.com/bfgroup/duck_invoke/releases\"]\nLicense:: image:https://img.shields.io/badge/license-BSL%201.0-blue.svg[\"Boost Software License 1.0\", link=\"LICENSE.txt\"]\nStandards:: image:https://img.shields.io/badge/standard-PFL-orange.svg[\"Pitchfork Layout\", link=\"https://github.com/vector-of-bool/pitchfork\"]\nimage:https://img.shields.io/badge/standard-C%2B%2B%2011-blue.svg?logo=C%2B%2B[\"C\\+\\+ 11\", link=\"https://isocpp.org/\"]\nimage:https://img.shields.io/badge/standard-C%2B%2B%2014-blue.svg?logo=C%2B%2B[\"C\\+\\+ 14\", link=\"https://isocpp.org/\"]\nimage:https://img.shields.io/badge/standard-C%2B%2B%2017-blue.svg?logo=C%2B%2B[\"C\\+\\+ 17\", link=\"https://isocpp.org/\"]\nimage:https://img.shields.io/badge/standard-C%2B%2B%2020-blue.svg?logo=C%2B%2B[\"C\\+\\+ 20\", link=\"https://isocpp.org/\"]\nStats:: image:https://img.shields.io/github/languages/code-size/bfgroup/duck_invoke.svg[GitHub code size in bytes, link=\"https://github.com/bfgroup/duck_invoke\"]\nimage:https://img.shields.io/github/issues/bfgroup/duck_invoke.svg[GitHub issues, link=\"https://github.com/bfgroup/duck_invoke/issues\"]\nimage:https://img.shields.io/github/stars/bfgroup/duck_invoke.svg?label=%E2%98%85[GitHub stars, link=\"https://github.com/bfgroup/duck_invoke/stargazers\"]\n\n// end::intro[]\n\n== License\n\n// tag::license[]\n\nDistributed under the Boost Software License, Version 1.0. (See accompanying\nfile LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)\n\n// end::license[]\n\n== Features\n\n// tag::features[]\n\n* Header only with no external dependencies (except the `std` library).\n* Single header, with included reference documentation.\n* BSL 1.0 license, so it can be used anywhere.\n* Gives equivalent functionality, with less user code, than current C++20\n  `tag_invoke` implementations.\n* For the most common, and basic, use case it's a single line of code.\n* Fully optimizes, with `-O2`, to equivalent direct code.\n* Tested to work with: Linux GCC 4.8 through 10; Linux Clang 3.8 through 11;\n  macOS Xcode 11.2.1 through 12.2; Windows MinGW-w64 7.3 and 6.3;\n  Windows 2019 (currently only works with `/std:c++latest` option).\n\n// end::features[]\n\n== Using\n\n// tag::using[]\n\nThe simplest use case involves a few simple items:\n\n. The definition of the customization point object (CPO).\n. Calling the CPO in a library that wants to be customized by users of it.\n. Defining a customization in code that uses the library.\n. Calling the library to use the feature that is customized.\n\n(1) With this library the definition of the CPO is a simple single declaration:\n\n[source,cpp]\n----\n#include \u003cbfg/tag_invoke.h\u003e\n\nnamespace compute {\n\nBFG_TAG_INVOKE_DEF(formula);\n\n} // namespace compute\n----\n\nThat has the effect of declaring `compute::formula_t` for the CPO tag type.\nAnd defines a `compute::formula` CPO that can be called. And that is\ncustomizable through `tag_invoke` functions.\n\n(2) Using the CPO in the library code, or even in user code, is as simple as\ncalling the CPO like a regular call:\n\n[source,cpp]\n----\ntemplate \u003ctypename Compute\u003e\nfloat do_compute(const Compute \u0026 c, float a, float b)\n{\n\treturn compute::formula(c, a, b);\n}\n----\n\nThe key aspect for defining such code in libraries is that you need to accept\nan argument for which the type is used for argument dependent lookup (ADL)\nresolution. In this example the `const Compute \u0026 c` argument will do that for\nus.\n\n(3) We can now turn our attention to the user code of the above \"library\". For\nthat we need to create an object that provides a customization of the\nappropriate customization point. The most effective way to do that is with a\nhidden friend function:\n\n[source,cpp]\n----\nstruct custom_compute\n{\nprivate:\n\tfriend float\n\t\ttag_invoke(compute::formula_t, const custom_compute \u0026, float a, float b)\n\t{\n\t\treturn a * b;\n\t}\n};\n----\n\nThe arguments match the use of the CPO in the library, plus the tag type of\nthe CPO as the first argument. That argument is what puts the customization\nwithin the realm of ADL.\n\n(4) Finally we can use the library and the customization we created for it:\n\n[source,cpp]\n----\nint main()\n{\n\tdo_compute(custom_compute{}, 2, 3);\n}\n----\n\n// end::using[]\n","funding_links":["https://github.com/sponsors/grafikrobot"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbfgroup%2Fduck_invoke","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbfgroup%2Fduck_invoke","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbfgroup%2Fduck_invoke/lists"}