Perfect Forwarding (std::forward)

Medium Move Semantics
Solve in Playground →

Problem Statement

Write a C++ program defining a template function utilizing perfect forwarding (`std::forward`) to preserve argument value categories.

Input Format

A single integer N.

Output Format

Print forwarded value.

Constraints

-100000 <= N <= 100000

Sample Input

777

Sample Output

Forwarded Value: 777

Explanation

Perfect forwarding passes arguments to other functions while preserving their exact lvalue/rvalue category.

Starter Code

#include <iostream>
#include <utility>

void process(int &val) {
    std::cout << "Forwarded Value: " << val << "n";
}

void process(int &&val) {
    std::cout << "Forwarded Value: " << val << "n";
}

template <typename T>
void wrapper(T &&arg) {
    // Write your perfect forwarding logic here
}

int main() {
    int n;
    if (std::cin >> n) {
        wrapper(n);
    }
    return 0;
}

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used