336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
C++로 플젝을 돌리다 GetSet만들기 귀찮아서 만들어 봄
쓰일지는 모름 모름
// CopyTest.cpp : 콘솔 응용 프로그램에 대한 진입점을 정의합니다.
//
#include "stdafx.h"
#include <iostream> // std::cout, std::ios
#include <sstream> // std::ostringstream\\
#include <boost/type_traits.hpp> // is_array, is_class, remove_bounds
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/next_prior.hpp>
#include <boost/fusion/mpl.hpp>
#include <boost/fusion/adapted.hpp> // BOOST_FUSION_ADAPT_STRUCT
// boost::fusion::result_of::value_at
#include <boost/fusion/sequence/intrinsic/value_at.hpp>
#include <boost/fusion/include/value_at.hpp>
// boost::fusion::result_of::size
#include <boost/fusion/sequence/intrinsic/size.hpp>
#include <boost/fusion/include/size.hpp>
// boost::fusion::at
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/include/at.hpp>
#include <chrono>
#define MemberMacro(Type, MemberName) \
private:\
Type MemberName;\
public:\
Type Get##MemberName() const{ \
return MemberName; \
}; \
Type & GetR##MemberName() { \
return MemberName; \
}; \
void Set##MemberName(Type value) { \
MemberName = value; \
}\
class ABCDE
{
public:
ABCDE()
{
A = 1;
B = 2;
C = 3;
D = 4;
E = 5;
}
MemberMacro(int, A);
MemberMacro(int, B);
MemberMacro(int, C);
MemberMacro(int, D);
MemberMacro(int, E);
};
class DE
{
public:
DE()
{
D = 0;
E = 0;
}
MemberMacro(int, D);
MemberMacro(int, E);
};
BOOST_FUSION_ADAPT_STRUCT(
ABCDE,
(int &,GetRA())
(int &,GetRB())
(int &,GetRC())
(int &,GetRD())
(int &,GetRE())
)
BOOST_FUSION_ADAPT_STRUCT(
DE,
(int &,GetRD())
(int &,GetRE())
)
template < typename S, typename N, typename R>
struct Getter
{
typedef typename boost::fusion::result_of::value_at< S, N >::type current_t;
typedef typename boost::mpl::next< N >::type next_t;
typedef boost::fusion::extension::struct_member_name< S, N::value > name_t;
static inline void Get(S& s, const char * findName, R & out)
{
std::string field = name_t::call();
if(strcmp(field.c_str(), findName) == 0)
{
out = boost::fusion::at< N >(s);
return;
}
Getter<S, next_t, R>::Get(s, findName, out);
}
};
template < typename S, typename R>
struct Getter< S, typename boost::fusion::result_of::size< S >::type, R>
{
static inline void Get(S& s, const char * findName, R & out)
{
}
};
template < typename SS, typename SN, typename GS>
struct Setter
{
typedef typename boost::fusion::result_of::value_at<SS, SN >::type current_t;
typedef typename boost::mpl::next<SN>::type next_t;
typedef boost::fusion::extension::struct_member_name<SS, SN::value > name_t;
static inline void Set(SS & ss, GS& gs)
{
std::string field = name_t::call();
Getter<GS, boost::mpl::int_< 0 >, current_t>::Get(gs, field.c_str(), boost::fusion::at<SN>(ss));
Setter<SS, next_t, GS>::Set(ss, gs);
}
};
template < typename SS, typename GS>
struct Setter<SS, typename boost::fusion::result_of::size< SS >::type, GS>
{
static inline void Set(SS& ss, GS& gs)
{
}
};
int _tmain(int argc, _TCHAR* argv[])
{
DE de;
ABCDE abcde;
auto start = std::chrono::system_clock::now();
for(int i = 0 ; i < 10000 ; i++)
{
Setter<DE, boost::mpl::int_<0>, ABCDE>::Set(de, abcde);
}
auto check = std::chrono::system_clock::now();
std::chrono::duration<double> sec = check - start;
std::cout << sec.count() << std::endl;
start = std::chrono::system_clock::now();
for(int i = 0 ; i < 10000 ; i++)
{
de.SetD(abcde.GetD());
de.SetE(abcde.GetE());
}
check = std::chrono::system_clock::now();
sec = check - start;
std::cout << sec.count() << std::endl;
return 0;
}
속도차이는 좀 나넹