C++ STL的std :: add_lvalue_reference模板位于
std :: add_lvalue_reference由模板std :: is_lvalue_reference :: value检查。
头文件:
#include
模板类别:
template< class T >
struct add_lvalue_reference
句法:
std::is_lvalue_reference::value
参数:模板std :: add_lvalue_reference接受单个参数T(特质类)
下面是演示C++中std :: add_lvalue_reference的程序:
程序1:
// C++ program to illustrate
// std::add_lvalue_reference
#include
#include
using namespace std;
// Driver Code
int main()
{
// Declare lvalue of type int, int&,
// int&& and int*
typedef add_lvalue_reference::type A;
typedef add_lvalue_reference::type B;
typedef add_lvalue_reference::type C;
typedef add_lvalue_reference::type D;
cout << std::boolalpha;
// Check if A is int const& or not
cout << "A: " << is_same::value
<< endl;
// Check if B is int* or not
cout << "B: " << is_same::value
<< endl;
// Check if C is int& or not
cout << "C: " << is_same::value
<< endl;
// Check if C is int && or not
cout << "D: " << is_same::value
<< endl;
return 0;
}
输出:
A: true
B: false
C: true
D: false
程式2:
// C++ program to illustrate
// std::add_lvalue_reference
#include
#include
using namespace std;
// Driver Code
int main()
{
// Declare lvalue using typename
using a = int;
using b = float;
using lref
= typename add_lvalue_reference::type;
using rref
= typename add_rvalue_reference::type;
cout << std::boolalpha;
// Check if the above declaration
// are correct or not
cout << "is int is lvalue? "
<< is_lvalue_reference::value
<< '\n';
cout << "is lref is lvalue? "
<< is_lvalue_reference::value
<< '\n';
cout << "is float is lvalue? "
<< is_rvalue_reference::value
<< '\n';
return 0;
}
输出:
is int is lvalue? false
is lref is lvalue? true
is float is lvalue? false
参考: http://www.cplusplus.com/reference/type_traits/add_lvalue_reference/
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。