Which of the following are advantages of C++20 Concepts?
a) Improved error messages during template instantiation
b) Automatic memory management for templates
c) Enable function overloading based on semantic constraints
d) Elimination of header files
Which syntax forms are valid for defining a function template using Concepts?
a) template
b) auto add(std::integral auto a, std::integral auto b)
c) void add(T a, T b) requires std::integral
d) std::integral add(std::integral a, std::integral b)
What are the key benefits of C++20 Modules?
a) Faster compilation times due to reduced header redundancy
b) Isolation of preprocessor macros across modules
c) Automatic parallel execution of code
d) Elimination of the One Definition Rule (ODR)
Which statements about std::span
are correct?
a) It owns the elements it references.
b) It can automatically deduce the size of a contiguous sequence.
c) It is a replacement for std::vector
.
d) It supports both static and dynamic extents.
What is true about the consteval
specifier in C++20?
a) It ensures a function is evaluated at runtime.
b) It implicitly makes a function constexpr
.
c) It can only be applied to virtual functions.
d) It guarantees compile-time evaluation for every invocation.
Which features are part of the C++20 Ranges library?
a) Lazy evaluation of operations
b) Direct container manipulation without iterators
c) Thread-safe container operations
d) Pipeline syntax using the |
operator
What are valid uses of the [[nodiscard]]
attribute?
a) To enforce error checking for function return values
b) To optimize compiler-generated code
c) To mark deprecated functions
d) To suppress compiler warnings for unused variables
Which statements about std::jthread
are correct?
a) It automatically joins its thread upon destruction.
b) It supports cooperative interruption via std::stop_token
.
c) It is a drop-in replacement for std::thread
with identical behavior.
d) It requires manual resource management.
What is true about the Three-Way Comparison Operator (<=>
)?
a) It can be defaulted to generate all six comparison operators.
b) It returns a boolean value.
c) It requires manual implementation for derived classes.
d) It supports lexicographical comparison of class members.
Which operations are valid for std::atomic_ref
?
a) Atomic updates on non-atomic objects
b) Thread-safe access to subobjects of the referenced object
c) Guaranteed lock-free implementation
d) Cooperative interruption of threads
What is true about constinit
?
a) It ensures constant initialization for static storage duration variables.
b) It implies constexpr
.
c) It can be applied to dynamically allocated memory.
d) It solves the static initialization order fiasco.
Which statements about Coroutines are correct?
a) They require manual stack management.
b) co_await
suspends execution until a result is available.
c) co_yield
returns a value and resumes execution later.
d) They are exclusively for multi-threaded applications.
What are valid uses of requires
clauses?
a) To constrain template parameters using logical combinations of concepts
b) To define runtime preconditions for functions
c) To specify exception guarantees
d) To check the validity of expressions at compile time
Which features are part of the C++20 Calendar and Time Zone library?
a) Time zone-aware time points
b) Mathematical constants like π
c) Literals for days (d
) and years (y
)
d) Formatting utilities for dates
What is true about the std::format
library?
a) It uses Python-style format strings.
b) It is type-safe compared to printf
.
c) It requires manual memory allocation for output.
d) It supports user-defined types via specialization.
Which statements about Lambda improvements in C++20 are correct?
a) Lambdas can have template parameters.
b) Stateless lambdas can be default-constructed.
c) Lambdas cannot capture this
implicitly.
d) consteval
lambdas are evaluated at runtime.
What is true about std::semaphore
in C++20?
a) It supports both counting and binary semaphores.
b) It is part of the
header.
c) It replaces std::mutex
for all use cases.
d) Its acquire()
method decrements the counter.
Which statements about Designated Initialization are correct?
a) It allows initializing class members in any order.
b) It works only with aggregate types.
c) It is compatible with private class members.
d) Missing designators result in zero-initialization.
What is true about the std::ranges
algorithms?
a) They operate directly on containers without iterators.
b) They are always evaluated eagerly.
c) They support pipeline composition using |
.
d) They replace all existing
functions.
Which statements about std::stop_source
and std::stop_token
are correct?
a) They enable cooperative thread cancellation.
b) A stop_token
can be used to poll for cancellation requests.
c) They are part of the
header.
d) std::jthread
automatically manages stop_source
lifetime.
What is true about the no_unique_address
attribute?
a) It allows overlapping storage for empty class members.
b) It guarantees unique memory addresses for all members.
c) It is used to optimize space in class layouts.
d) It applies only to virtual base classes.
Which statements about std::latch
and std::barrier
are correct?
a) std::latch
can be reused multiple times.
b) std::barrier
supports phase-based synchronization.
c) Both are defined in the
header.
d) std::latch
decrements a counter on each arrive_and_wait()
.
What is true about the std::source_location
class?
a) It provides compile-time information about the source code.
b) It replaces the __FILE__
and __LINE__
macros.
c) It requires runtime computation to capture location data.
d) It is part of the
header.
Which statements about the Spaceship Operator (<=>
) are correct?
a) It returns a value of type std::strong_ordering
.
b) It can be used to generate equality operators (==
, !=
).
c) It requires explicit implementation for all comparison categories.
d) It simplifies the definition of comparison operators for classes.
What is true about the std::is_constant_evaluated()
function?
a) It returns true
during compile-time evaluation.
b) It is used to optimize runtime performance.
c) It can differentiate between constexpr
and consteval
contexts.
d) It is part of the
header.
a, c
Concepts improve error messages and enable overloading based on constraints (Section 4.1.2). Modules eliminate headers, not Concepts.
a, b, c
Valid syntax includes constrained templates, abbreviated function templates, and trailing requires
clauses (Section 4.1.4). Option d is invalid.
a, b
Modules reduce header redundancy and isolate macros (Section 4.2.2). ODR still applies.
b, d
std::span
deduces size and supports static/dynamic extents (Section 5.2.1). It does not own elements.
b, d
consteval
ensures compile-time evaluation and is a subset of constexpr
(Section 4.5.1).
a, b, d
Ranges support lazy evaluation, direct container ops, and pipeline syntax (Section 5.1).
a
[[nodiscard]]
enforces checking return values (Section 4.8.1). It does not optimize code or mark deprecation.
a, b
std::jthread
auto-joins and supports interruption (Section 6.6). It is not identical to std::thread
.
a, d
<=>
can be defaulted for lexicographical comparisons (Section 4.3.4). It returns an ordering type, not a boolean.
a
std::atomic_ref
applies atomic ops to non-atomic objects (Section 6.2.1). Subobjects are not thread-safe.
a, d
constinit
ensures compile-time initialization and avoids static order issues (Section 4.5.4). It does not imply constexpr
.
b, c
Coroutines use co_await
/co_yield
for suspension/resumption (Section 6.1). They are not limited to multi-threading.
a, d
requires
clauses constrain templates and validate expressions (Section 4.1.9). They are not for runtime checks.
a, c
The library includes time zones and literals (Section 5.6). Formatting is separate.
a, b, d
std::format
uses Python syntax, is type-safe, and supports custom types (Section 5.5).
a, b
Lambdas support templates and stateless default construction (Section 4.7). this
capture detection is improved.
a, d
Semaphores are counting and use acquire()
(Section 6.3). They are in
.
b, d
Designated initialization works with aggregates and zero-initializes missing fields (Section 4.4).
a, c
Ranges operate on containers and support pipelines (Section 5.1). Evaluation can be lazy.
a, b, d
stop_source/token
enable cancellation and are managed by jthread
(Section 6.5).
a, c
no_unique_address
optimizes space for empty members (Section 4.8.3).
b, d
barrier
supports phases; latch
decrements a counter (Section 6.4). They are in
/
.
a, b
std::source_location
replaces macros and is compile-time (Section 5.7.4). It is in
.
a, b, d
<=>
returns ordering categories and simplifies operator definitions (Section 4.3). Categories are automatic.
a, d
is_constant_evaluated()
detects compile-time context (Section 5.7.2). It is in
.
std::vector>
and invalid types.Key Points:
std::ranges::contiguous_range
and custom dimension checks.requires
clauses for template constraints.math
that exports add
, multiply
, and power
functions. Import the module in another translation unit and verify symbol visibility.Key Points:
filter
+ transform
). Extract the first 20 primes and print them.Key Points:
|
operator.co_await
.Key Points:
co_await
for suspension/resumption.Complex
class with compiler-generated operator<=>
and test ordering in sorted containers.Key Points:
default
ed three-way comparison.std::span
std::span
to create a function that processes elements from different containers (std::array
, std::vector
) without copying.Key Points:
std::span
’s bounds checking.constexpr
constexpr
JSON parser that validates syntax and extracts values at compile time. Test with static assertions.Key Points:
consteval
for strict compile-time execution.std::counting_semaphore
to enforce thread-safe producer-consumer access.Key Points:
std::atomic
std::atomic>
and verify atomic updates.Key Points:
to schedule meetings across time zones (e.g., “New York 9:00 AM” to “London” local time).Key Points:
std::chrono::time_zone
conversions.Key Points:
concat
function using fold expressions and concepts to ensure all arguments are string-like (std::string
, std::string_view
).Key Points:
auto
.std::views
Key Points:
std::formatter
to display double
in engineering notation (exponent multiples of 3). Test with std::format
.Key Points:
std::barrier
to synchronize worker threads operating on matrix blocks.Key Points:
Wait for resolution…