mirror of
https://git.suyu.dev/suyu/sirit.git
synced 2025-12-24 08:16:23 +01:00
By taking the std::string by value in the constructor, this allows for
certain situations where copies can be elided entirely (when moving an
instance into the constructor)
e.g.
std::string var = ...
...
... = LiteralString(std::move(var)) // Or whatever other initialization
// is done.
No copy will be done in this case, the move transfers it into the
constructor, and then the move within the initializer list transfers it
into the member variable.
tl;dr: This allows the calling code to potentially construct less
std::string instances by allowing moving into the parameters themselves.
29 lines
648 B
C++
29 lines
648 B
C++
/* This file is part of the sirit project.
|
|
* Copyright (c) 2018 ReinUsesLisp
|
|
* This software may be used and distributed according to the terms of the GNU
|
|
* Lesser General Public License version 3 or any later version.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
#include "operand.h"
|
|
#include "stream.h"
|
|
|
|
namespace Sirit {
|
|
|
|
class LiteralString : public Operand {
|
|
public:
|
|
LiteralString(std::string string);
|
|
~LiteralString() override;
|
|
|
|
void Fetch(Stream& stream) const override;
|
|
u16 GetWordCount() const override;
|
|
|
|
bool operator==(const Operand& other) const override;
|
|
|
|
private:
|
|
const std::string string;
|
|
};
|
|
|
|
} // namespace Sirit
|