{"id":15983986,"url":"https://github.com/aminya/cmove","last_synced_at":"2025-06-26T08:03:29.756Z","repository":{"id":40254420,"uuid":"319073067","full_name":"aminya/cmove","owner":"aminya","description":"Move const values in C++","archived":false,"fork":false,"pushed_at":"2022-05-17T22:10:20.000Z","size":45,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T20:46:09.988Z","etag":null,"topics":["const","cpp","cpp20","cxx","immutable","move","move-semantics","mutable","performance"],"latest_commit_sha":null,"homepage":"","language":"CMake","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aminya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-06T16:04:01.000Z","updated_at":"2023-05-18T18:19:03.000Z","dependencies_parsed_at":"2022-09-03T23:31:06.480Z","dependency_job_id":null,"html_url":"https://github.com/aminya/cmove","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/aminya/cmove","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminya%2Fcmove","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminya%2Fcmove/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminya%2Fcmove/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminya%2Fcmove/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aminya","download_url":"https://codeload.github.com/aminya/cmove/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminya%2Fcmove/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262026905,"owners_count":23246951,"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","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":["const","cpp","cpp20","cxx","immutable","move","move-semantics","mutable","performance"],"created_at":"2024-10-08T02:04:05.642Z","updated_at":"2025-06-26T08:03:29.739Z","avatar_url":"https://github.com/aminya.png","language":"CMake","readme":"# cmove\n\nMove const values in C++\n\nPerformance and const-correctness are now friends! :tada: :rocket:\n\n[![ci](https://github.com/aminya/cmove/actions/workflows/ci.yml/badge.svg)](https://github.com/aminya/cmove/actions/workflows/ci.yml)\n\n## Description\n\nThis header only library allows you to move `const` values.\n\n### Why?\n\n`cmove::cmove` allows for making your programs const-correct without being worried about extra copies.\n\nAs seen in [this link](https://cpp.godbolt.org/z/cnvvxbKcn), `cmove::cmove` generates a much smaller and faster code.\n\nThis also allows cleaning up the code, as you can remove your exessive constructor duplication. The following code will be efficient and clean with the help of `cmove::cmove`:\n```cpp\nstruct MyStruct\n{\n    std::string value;\n    MyStruct(std::string value_in): value(std::move(value_in)) {}\n};\n```\n```cpp\nconst auto my_struct_1 = MyStruct{\"Hello World im long string\"};\nMyStruct(cmove::cmove(my_struct_1))\n```\n\nUsing `cmove` allows [the core guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#con1-by-default-make-objects-immutable\n) while increasing performance. This `cmove::cmove` behavior is similar to the Rust's move behavior.\n\n## Example\n\nRun it online: https://cpp.godbolt.org/z/Ynq5eTroE\n\n```cpp\n#include \u003ccmove/lib.hpp\u003e\n\n#include \u003cstring\u003e\n#include \u003cfmt/core.h\u003e\n\nstruct MyStruct\n{\n    std::string value;\n};\n\nint main() {\n  const auto my_struct_1 = MyStruct{\"Hello World im long string string string\"};\n\n  // ...\n  // my_struct_1 is const for you here\n  // ...\n  // error:\n  // my_struct_1.value = \"changed value\";\n\n  // you don't need my_struct_1 anymore, so you can move it to my_struct_2 without copying\n  const auto my_struct_2 = MyStruct{cmove::cmove(my_struct_1)};\n\n  // error:\n  // my_struct_2.value = \"changed value\";\n\n  // use my_struct_2 somewhere\n  fmt::print(\"{}\", my_struct_2.value);\n}\n```\n\n## Usage in your project\n\ncmove is a header-only library, so you can download and use the [header file](https://github.com/aminya/move_const/blob/c3f45d3445fde61dc0de3158af64252abd7a8c79/cmove/include/cmove/lib.hpp).\n\nTo automatically integrate it to your CMake project, add the following code to your CMake file:\n\n```cmake\n# https://github.com/aminya/cmove\ninclude(FetchContent)\nFetchContent_Declare(_cmove URL https://github.com/aminya/cmove/releases/download/v1.0.2/cmove-1.0.2.zip)\nFetchContent_MakeAvailable(_cmove)\nset(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${_cmove_SOURCE_DIR})\n```\n\nThen link it to your targets:\n```\nfind_package(cmove CONFIG REQUIRED)\ntarget_link_libraries(main PRIVATE  cmove::cmove)\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faminya%2Fcmove","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faminya%2Fcmove","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faminya%2Fcmove/lists"}