In embedded telemetry systems, sensor data is rarely transmitted alone. It is commonly paired with metadata such as a timestamp, a status flag, or an identifier. Writing separate structs for every possible combination (for example, FloatWithTimestamp, IntWithStatus) leads to unnecessary code duplication and poor scalability.
Your task is to implement a class template named SensorPair that generically stores a sensor value together with its associated metadata.
The class template must accept two template parameters:
typename T_Value — the type of the sensor measurement (for example, float, int)typename T_Meta — the type of the metadata (for example, int, char)The goal is to practice multi-parameter templates, type-generic design, and compile-time type safety, which are commonly used in embedded C++ firmware codebases.
Requirements:
The SensorPair class template must:
value of type T_Valuemetadata of type T_MetaProvide a public member function print() that prints the pair in the exact format:
Pair: <value> | <metadata>
Program Flow:
N representing the number of test cases.N times:type_codetype_code, read the appropriate input values:"f-i" → read a float value and an int metadata"i-c" → read an int value and a single character metadata"i-i" → read an int value and an int metadataSensorPairprint() on the created objectInput Format:
N (1 ≤ N ≤ 20)N lines:type_codestdin)"i-c" cases, the metadata is always a single character, not a stringOutput Format:
Output format must be exactly:
Pair: <value> | <metadata>
Example:
Input
3
f-i 25.5 1001
i-c 1 E
i-i 4095 1Output
Pair: 25.50 | 1001
Pair: 1 | E
Pair: 4095 | 1 Constraints:
1 ≤ N ≤ 20template <typename T1, typename T2>
Input
3 f-i 25.5 1001 i-c 1 E i-i 4095 1
Expected Output
Pair: 25.50 | 1001 Pair: 1 | E Pair: 4095 | 1