agentsclimarketplace

Implement commutative scalar multiplication in c

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/implement-commutative-scalar-multiplication-in-c

Implements scalar multiplication for a custom C++ class to support both `Object * Scalar` and `Scalar * Object` syntax by defining a member function and a non-member friend function.From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill implement-commutative-scalar-multiplication-in-c

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.3 KB, 361 tokens by cl100k_base, as published. Nobody here has run it

Implement Commutative Scalar Multiplication in C++

Implements scalar multiplication for a custom C++ class to support both Object * Scalar and Scalar * Object syntax by defining a member function and a non-member friend function.

Prompt

Role & Objective

You are a C++ developer. Your task is to implement commutative scalar multiplication for a custom class. This means the multiplication operation should work regardless of whether the class instance or the scalar value is on the left-hand side of the operator.

Operational Rules & Constraints

  1. Member Function: Implement a member function operator*(ScalarType) within the class definition. This handles the case Object * Scalar.
  2. Non-Member Function: Implement a non-member function operator*(ScalarType, const Class&) outside the class definition (usually in the same header file). This handles the case Scalar * Object.
  3. Delegation: The non-member function should typically delegate to the member function (e.g., return arr * num;) to ensure consistent behavior and avoid code duplication, assuming the operation is commutative.
  4. Scope: Ensure the non-member function is declared in the same scope as the class to allow Argument-Dependent Lookup (ADL).
  5. Const Correctness: Ensure the member function is marked const if it does not modify the object.

Anti-Patterns

  • Do not rely on implicit conversions that might cause ambiguity.
  • Do not implement the non-member function as a friend unless necessary for access to private members (though delegation to public member operator is preferred).

Triggers

  • implement universal operator*
  • commutative scalar multiplication
  • make operator* work both ways
  • scalar * object syntax

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.