Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3663d96

Browse files
committed
clang-tidy modernize-pass-by-value fix
1 parent 913aec7 commit 3663d96

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

examples/pluginmanager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
#include "cli/clilocalsession.h"
4646
#include "cli/cli.h"
47+
#include <utility>
4748
#include <vector>
4849

4950
using namespace cli;
@@ -55,7 +56,7 @@ using namespace std;
5556
class Plugin
5657
{
5758
public:
58-
Plugin(const string& _name) : name(_name) { cout << "Plugin " << name << " loaded" << endl; }
59+
Plugin(string _name) : name(std::move(_name)) { cout << "Plugin " << name << " loaded" << endl; }
5960
virtual ~Plugin() { cout << "Plugin " << name << " unloaded" << endl; }
6061
const string& Name() const { return name; }
6162
private:

include/cli/cli.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#ifndef CLI_H_
3131
#define CLI_H_
3232

33-
#include <iostream>
3433
#include <string>
3534
#include <vector>
3635
#include <memory>
@@ -44,6 +43,8 @@
4443
#include "detail/fromstring.h"
4544
#include "historystorage.h"
4645
#include "volatilehistorystorage.h"
46+
#include <iostream>
47+
#include <utility>
4748

4849
namespace cli
4950
{
@@ -128,7 +129,7 @@ namespace cli
128129
) :
129130
globalHistoryStorage(std::move(historyStorage)),
130131
rootMenu(std::move(_rootMenu)),
131-
exitAction(_exitAction)
132+
exitAction(std::move(_exitAction))
132133
{
133134
}
134135

@@ -191,7 +192,7 @@ namespace cli
191192
class Command
192193
{
193194
public:
194-
explicit Command(const std::string& _name) : name(_name), enabled(true) {}
195+
explicit Command(std::string _name) : name(std::move(_name)), enabled(true) {}
195196
virtual ~Command() = default;
196197
virtual void Enable() { enabled = true; }
197198
virtual void Disable() { enabled = false; }
@@ -313,9 +314,9 @@ namespace cli
313314
private:
314315
struct Descriptor
315316
{
316-
Descriptor() {}
317-
Descriptor(const std::weak_ptr<Command>& c, const std::weak_ptr<CmdVec>& v) :
318-
cmd(c), cmds(v)
317+
Descriptor() = default;
318+
Descriptor(std::weak_ptr<Command> c, std::weak_ptr<CmdVec> v) :
319+
cmd(std::move(c)), cmds(std::move(v))
319320
{}
320321
void Enable()
321322
{
@@ -359,8 +360,8 @@ namespace cli
359360

360361
Menu() : Command({}), parent(nullptr), description(), cmds(std::make_shared<Cmds>()) {}
361362

362-
Menu(const std::string& _name, const std::string& desc = "(menu)") :
363-
Command(_name), parent(nullptr), description(desc), cmds(std::make_shared<Cmds>())
363+
Menu(const std::string& _name, std::string desc = "(menu)") :
364+
Command(_name), parent(nullptr), description(std::move(desc)), cmds(std::make_shared<Cmds>())
364365
{}
365366

366367
template <typename F>
@@ -568,10 +569,10 @@ namespace cli
568569
VariadicFunctionCommand(
569570
const std::string& _name,
570571
F fun,
571-
const std::string& desc,
572-
const std::vector<std::string>& parDesc
572+
std::string desc,
573+
std::vector<std::string> parDesc
573574
)
574-
: Command(_name), func(std::move(fun)), description(desc), parameterDesc(parDesc)
575+
: Command(_name), func(std::move(fun)), description(std::move(desc)), parameterDesc(std::move(parDesc))
575576
{
576577
}
577578

@@ -626,10 +627,10 @@ namespace cli
626627
FreeformCommand(
627628
const std::string& _name,
628629
F fun,
629-
const std::string& desc,
630-
const std::vector<std::string>& parDesc
630+
std::string desc,
631+
std::vector<std::string> parDesc
631632
)
632-
: Command(_name), func(std::move(fun)), description(desc), parameterDesc(parDesc)
633+
: Command(_name), func(std::move(fun)), description(std::move(desc)), parameterDesc(std::move(parDesc))
633634
{
634635
}
635636

include/cli/detail/split.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030
#ifndef CLI_DETAIL_SPLIT_H_
3131
#define CLI_DETAIL_SPLIT_H_
3232

33+
#include <algorithm>
3334
#include <string>
35+
#include <utility>
3436
#include <vector>
35-
#include <algorithm>
3637

3738
namespace cli
3839
{
@@ -42,7 +43,7 @@ namespace detail
4243
class Text
4344
{
4445
public:
45-
explicit Text(const std::string& _input) : input(_input)
46+
explicit Text(std::string _input) : input(std::move(_input))
4647
{
4748
}
4849
void SplitInto(std::vector<std::string>& strs)

include/cli/filehistorystorage.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,17 @@
3232

3333
#include "historystorage.h"
3434
#include <fstream>
35+
#include <utility>
3536

3637
namespace cli
3738
{
3839

3940
class FileHistoryStorage : public HistoryStorage
4041
{
4142
public:
42-
FileHistoryStorage(const std::string& _fileName, std::size_t size = 1000) :
43+
FileHistoryStorage(std::string _fileName, std::size_t size = 1000) :
4344
maxSize(size),
44-
fileName(_fileName)
45+
fileName(std::move(_fileName))
4546
{
4647
}
4748
void Store(const std::vector<std::string>& cmds) override

0 commit comments

Comments
 (0)