va_copy
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Utilities library
Type support (basic types, RTTI)
Library feature-test macros (C++20)
(C++11)
(C++20)
(C++26)
(C++20)
Coroutine support (C++20)
Contract support (C++26)
(C++20)(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
General utilities
Relational operators (deprecated in C++20)
(C++20)(C++20)(C++20)
(C++20)(C++20)(C++20)
(C++20)
Swap and type operations
Common vocabulary types
Defined in header
<cstdarg>
void va_copy( std::va_list dest, std::va_list src );
(since C++11)
The va_copy
macro copies src to dest.
va_end should be called on dest before the function returns or any subsequent re-initialization of dest (via calls to va_start or va_copy).
Contents
[edit] Parameters
dest
-
an instance of the va_list type to initialize
src
-
the source va_list that will be used to initialize dest
[edit] Expanded value
(none)
[edit] Example
Run this code
#include <cmath> #include <cstdarg> #include <iostream> double sample_stddev(int count, ...) { double sum = 0; std::va_list args1; va_start (args1, count); std::va_list args2; va_copy(args2, args1); for (int i = 0; i < count; ++i) { double num = va_arg (args1, double); sum += num; } va_end (args1); double mean = sum / count; double sum_sq_diff = 0; for (int i = 0; i < count; ++i) { double num = va_arg (args2, double); sum_sq_diff += (num - mean) * (num - mean); } va_end (args2); return std::sqrt (sum_sq_diff / count); } int main() { std::cout << sample_stddev(4, 25.0, 27.3, 26.9, 25.7) << '\n'; }
Output:
0.920258
[edit] See also
C documentation for va_copy