永发信息网

std::list<User> queryUser(std::function<bool(const User&)> filter); 这是什么意思?

答案:1  悬赏:0  手机版
解决时间 2021-03-17 14:57
  • 提问者网友:眉目添风霜
  • 2021-03-17 02:15
#ifndef AGENDA_STORAGE_H
#define AGENDA_STORAGE_H

#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)

#include <list>
#include <string>
#include <functional>

#include "User.h"
#include "Meeting.h"

class Storage {
private:
static Storage *instance_;
DISALLOW_COPY_AND_ASSIGN(Storage);
Storage();
// storage structure with list, or you have better structures
// e.g. balanced tree
std::list<User> userList_;
std::list<Meeting> meetingList_;
// File IO
bool readFromFile(const char *fpath);
bool writeToFile(const char *fpath);
public:
// singleton
static Storage *getInstance(void);
~Storage();
// CRUD for User & Meeting
// using C++11 Function Template and Lambda Expressions
void createUser(const User&);
std::list<User> queryUser(std::function<bool(const User&)> filter);
// return found users
int updateUser(std::function<bool(const User&)> filter,
std::function<void(User&)> switcher);
// return the number of updated users
int deleteUser(std::function<bool(const User&)> filter);
// return the number of deleted users
void createMeeting(const Meeting&);
std::list<Meeting> queryMeeting(
std::function<bool(const Meeting&)> filter);
// return found meetings
int updateMeeting(std::function<bool(const Meeting&)> filter,
std::function<void(Meeting&)> switcher);
// return the number of updated meetings
int deleteMeeting(std::function<bool(const Meeting&)> filter);
// return the number of deleted meetings
// File IO
bool sync(void);
};

#endif
这是头文件

宏里面的
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&) 这又是什么
最佳答案
  • 五星知识达人网友:拜訪者
  • 2021-03-17 03:35
std::list<User> queryUser(std::function<bool(const User&)> filter);
--------------------------------------------------------------
=>std::function:c++11引入的一个新特性,函数模板。
=>std::function<bool(const User&)> filter:声明filter是一个函数,该函数的形参为const User&,返回值为bool。后续代码可以这样使用filter:bool ret = filter(一个User-obj)。

#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
--------------------------------------------------------------
声明了一个宏DISALLOW_COPY_AND_ASSIGN(TypeName),之后,凡是出现DISALLOW_COPY_AND_ASSIGN(xxx)的地方,统统全部,
用“xxx(const xxx&); void operator=(const xxx&)”替换。
——是纯字符替换,宏不检查xxx的确切定义。。是类型名,不是类型,都不理会。
——类不定义显式的拷贝构造函数,则运行时使用编译时编译器自动添加的缺省
的拷贝构造函数,在这种情况下,类对象是可以被任意拷贝的。
你的例子,类显式的定义了自己的拷贝构造函数,此时若实现为空,则运行
时在遇到对象拷贝情况时将调用该函数,但实际上不进行任何对象拷贝工作。
=重载的情况是一样的,不再赘述。
这题5分,是不少些。。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯