DQCsim
Public Member Functions | Static Public Member Functions | List of all members
dqcsim::wrap::QubitSet Class Reference

Represents an ordered set of qubit references. More...

Inheritance diagram for dqcsim::wrap::QubitSet:
dqcsim::wrap::Handle

Public Member Functions

 QubitSet (HandleIndex handle) noexcept
 Wraps the given qubit set handle. More...
 
 QubitSet ()
 Constructs an empty qubit set. More...
 
 QubitSet (const QubitSet &src)
 Copy-constructs a qubit set. More...
 
void operator= (const QubitSet &src)
 Copy assignment operator for qubit sets. More...
 
 QubitSet (QubitSet &&)=default
 Default move constructor.
 
QubitSetoperator= (QubitSet &&)=default
 Default move assignment.
 
void push (const QubitRef &qubit)
 Pushes a qubit into the set. More...
 
QubitSet && with (const QubitRef &qubit)
 Pushes a qubit into the set (builder pattern). More...
 
QubitRef pop ()
 Pops a qubit from the set. More...
 
size_t size () const
 Returns the number of qubits in the set. More...
 
bool contains (const QubitRef &qubit) const
 Returns whether the given qubit is contained in the set. More...
 
std::vector< QubitRefdrain_into_vector ()
 Drains the qubit set into a vector. More...
 
std::vector< QubitRefcopy_into_vector () const
 Copies the qubit set into a vector. More...
 
- Public Member Functions inherited from dqcsim::wrap::Handle
 Handle () noexcept
 Constructs an empty wrapper. More...
 
 Handle (HandleIndex handle) noexcept
 Wraps the given raw handle. More...
 
virtual ~Handle () noexcept
 Delete the handle and its wrapper.
 
void free ()
 Explicitly delete the handle, allowing errors to be caught. More...
 
bool is_valid () const noexcept
 Returns whether this wrapper (still) contains a valid handle. More...
 
HandleIndex get_handle () const noexcept
 Returns the raw handle without relinquishing ownership. More...
 
HandleIndex take_handle () noexcept
 Returns the raw handle and relinquishes ownership. More...
 
 Handle (const Handle &)=delete
 
void operator= (const Handle &)=delete
 
 Handle (Handle &&src)
 Move constructor; simply moves ownership of the handle from the source object to the constructed object. More...
 
Handleoperator= (Handle &&src)
 Move constructor; simply moves ownership of the handle from the source object to the assignment target. More...
 
std::string dump () const
 Returns a string containing a debug dump of the handle. More...
 
HandleType type () const
 Returns the type of this handle. More...
 

Static Public Member Functions

template<class T >
static QubitSet from_iter (const T &qubits)
 Constructs a qubit set object from an iterable of qubit references. More...
 

Additional Inherited Members

- Protected Attributes inherited from dqcsim::wrap::Handle
HandleIndex handle
 The wrapped handle.
 

Detailed Description

Represents an ordered set of qubit references.

DQCsim's API primarily uses these objects to represent the gate operand lists for multi-qubit gates. They can also be used to represent multi-qubit registers, but typically a std::vector<QubitRef> will be more suitable for that, as it supports fast and convenient indexation. You can convert between a QubitSet and a vector easily using from_iter, drain_into_vector, and copy_into_vector.

You can use the builder pattern to construct qubit sets in a single line:

QubitSet().with(1_q).with(2_q).with(3_q);

Definition at line 2982 of file dqcsim.

Constructor & Destructor Documentation

◆ QubitSet() [1/3]

dqcsim::wrap::QubitSet::QubitSet ( HandleIndex  handle)
inlinenoexcept

Wraps the given qubit set handle.

Note
This constructor does not verify that the handle is actually valid.
Parameters
handleThe raw handle to wrap.

Definition at line 2993 of file dqcsim.

◆ QubitSet() [2/3]

dqcsim::wrap::QubitSet::QubitSet ( )
inline

Constructs an empty qubit set.

Exceptions
std::runtime_errorWhen construction of the new handle fails for some reason.

Definition at line 3002 of file dqcsim.

◆ QubitSet() [3/3]

dqcsim::wrap::QubitSet::QubitSet ( const QubitSet src)
inline

Copy-constructs a qubit set.

Parameters
srcThe object to copy from.
Exceptions
std::runtime_errorWhen the source handle is invalid or construction of the new handle failed for some reason.

Definition at line 3028 of file dqcsim.

Member Function Documentation

◆ from_iter()

template<class T >
static QubitSet dqcsim::wrap::QubitSet::from_iter ( const T &  qubits)
inlinestatic

Constructs a qubit set object from an iterable of qubit references.

Parameters
qubitsAn iterable of const QubitRef& to take the qubits from.
Exceptions
std::runtime_errorWhen construction of the new handle fails for some reason.

Definition at line 3013 of file dqcsim.

◆ operator=()

void dqcsim::wrap::QubitSet::operator= ( const QubitSet src)
inline

Copy assignment operator for qubit sets.

Parameters
srcThe object to copy from.
Exceptions
std::runtime_errorWhen the source handle is invalid, any previously wrapped handle in the destination object could not be freed, or construction of the new handle failed for some reason.

Definition at line 3039 of file dqcsim.

◆ push()

void dqcsim::wrap::QubitSet::push ( const QubitRef qubit)
inline

Pushes a qubit into the set.

Note that qubit sets are ordered. An exception is thrown if the qubit is already in the set.

Parameters
qubitThe qubit reference to push.
Exceptions
std::runtime_errorWhen the handle is invalid.

Definition at line 3062 of file dqcsim.

◆ with()

QubitSet&& dqcsim::wrap::QubitSet::with ( const QubitRef qubit)
inline

Pushes a qubit into the set (builder pattern).

Note that qubit sets are ordered. An exception is thrown if the qubit is already in the set.

Parameters
qubitThe qubit reference to push.
Returns
&self, to continue building.
Exceptions
std::runtime_errorWhen the handle is invalid.

Definition at line 3074 of file dqcsim.

◆ pop()

QubitRef dqcsim::wrap::QubitSet::pop ( )
inline

Pops a qubit from the set.

Qubits are popped in the same order in which they are pushed (like a FIFO).

Returns
The popped qubit reference.
Exceptions
std::runtime_errorWhen the handle is invalid.

Definition at line 3086 of file dqcsim.

◆ size()

size_t dqcsim::wrap::QubitSet::size ( ) const
inline

Returns the number of qubits in the set.

Returns
The number of qubits in the set.
Exceptions
std::runtime_errorWhen the handle is invalid.

Definition at line 3096 of file dqcsim.

◆ contains()

bool dqcsim::wrap::QubitSet::contains ( const QubitRef qubit) const
inline

Returns whether the given qubit is contained in the set.

Parameters
qubitThe qubit reference that containment should be checked for.
Returns
Whether the set contains the given qubit reference.
Exceptions
std::runtime_errorWhen the handle is invalid.

Definition at line 3107 of file dqcsim.

◆ drain_into_vector()

std::vector<QubitRef> dqcsim::wrap::QubitSet::drain_into_vector ( )
inline

Drains the qubit set into a vector.

Note
This requires destructive iteration of the source object, so it isn't not const; if an exception occurs, the state of the source object may be changed.
Returns
A std::vector<QubitRef> containing the qubits that were in the set, in insertion order.
Exceptions
std::runtime_errorWhen the handle is invalid.

Definition at line 3122 of file dqcsim.

◆ copy_into_vector()

std::vector<QubitRef> dqcsim::wrap::QubitSet::copy_into_vector ( ) const
inline

Copies the qubit set into a vector.

Note
This requires destructive iteration of the source object, so it isn't not const; if an exception occurs, the state of the source object may be changed.
Returns
A std::vector<QubitRef> containing the qubits that are in the set, in insertion order.
Exceptions
std::runtime_errorWhen the handle is invalid.

Definition at line 3141 of file dqcsim.


The documentation for this class was generated from the following file:
dqcsim::wrap::QubitSet::QubitSet
QubitSet()
Constructs an empty qubit set.
Definition: dqcsim:3002