DQCsim
Public Member Functions | Friends | List of all members
dqcsim::wrap::QubitRef Class Reference

Represents a qubit. More...

Public Member Functions

 QubitRef (QubitIndex index)
 Wraps a raw reference. More...
 
 QubitRef (const QubitRef &)=default
 Default copy constructor.
 
QubitRefoperator= (const QubitRef &)=default
 Default copy assignment.
 
 QubitRef (QubitRef &&)=default
 Default move constructor.
 
QubitRefoperator= (QubitRef &&)=default
 Default move assignment.
 
bool operator== (const QubitRef &other) const noexcept
 Qubit reference equality operator. More...
 
bool operator!= (const QubitRef &other) const noexcept
 Qubit reference inequality operator. More...
 
QubitIndex get_index () const noexcept
 Returns the raw qubit index. More...
 

Friends

std::ostream & operator<< (std::ostream &out, const QubitRef &qubit)
 Allow qubit references to be printed. More...
 

Detailed Description

Represents a qubit.

This is a wrapper around the QubitIndex type, which prevents mutation and mathematical operations that don't make sense.

DQCsim's C++ API expects and gives out qubit references in this form. You can convert between it and QubitIndexes using the constructor and the get_index function as you please. Note that there is no performance difference between one or the other as they both represent a 64-bit integer in memory; this class purely adds some type-safety.

If you have the dqcsim::wrap namespace in scope, a custom literal is available for qubit references: instead of QubitRef(33) you can type 33_q as well.

Definition at line 2874 of file dqcsim.

Constructor & Destructor Documentation

◆ QubitRef()

dqcsim::wrap::QubitRef::QubitRef ( QubitIndex  index)
inline

Wraps a raw reference.

Parameters
indexThe index of the qubit to wrap.
Exceptions
std::runtime_errorWhen the qubit index is invalid (zero).

Definition at line 2890 of file dqcsim.

Member Function Documentation

◆ operator==()

bool dqcsim::wrap::QubitRef::operator== ( const QubitRef other) const
inlinenoexcept

Qubit reference equality operator.

Parameters
otherThe qubit reference to compare with.
Returns
Whether the references refer to the same qubit.

Definition at line 2922 of file dqcsim.

◆ operator!=()

bool dqcsim::wrap::QubitRef::operator!= ( const QubitRef other) const
inlinenoexcept

Qubit reference inequality operator.

Parameters
otherThe qubit reference to compare with.
Returns
Whether the references refer to different qubits.

Definition at line 2932 of file dqcsim.

◆ get_index()

QubitIndex dqcsim::wrap::QubitRef::get_index ( ) const
inlinenoexcept

Returns the raw qubit index.

Returns
The raw qubit index.

Definition at line 2953 of file dqcsim.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const QubitRef qubit 
)
friend

Allow qubit references to be printed.

Parameters
outThe output stream to write to.
qubitThe qubit reference to dump.
Returns
The output stream object.

Definition at line 2943 of file dqcsim.


The documentation for this class was generated from the following file: