C++ macro to log every line of code

前端 未结 2 1206
小鲜肉
小鲜肉 2021-02-02 15:05

During one of my recent discussions with my manager, he mentioned that one of his former clients used a C++ macro to log info about every line of code. All they had to do was en

2条回答
  •  北恋
    北恋 (楼主)
    2021-02-02 15:35

    You may check how BOOST_CHECKA from Boost.Test is implemented. Internally it uses expression templates.

    For test:

    #define BOOST_TEST_MAIN
    
    #include 
    #include 
    
    BOOST_AUTO_TEST_CASE(test1)
    {
        int a=0;
        int b=1;
        int c=2;
        BOOST_CHECKA( a+b == c );
    }
    

    Output is:

    Running 1 test case...
    main.cpp(11): error: in "test1": check a+b == c failed [0+1!=2]
    
    *** 1 failure detected in test suite "Master Test Suite"
    

    Note values in square brackets: [0+1!=2]

    It has some limitations.

    For test:

    BOOST_CHECKA( (a+b) == c );
    

    output is:

    check (a+b) == c failed [1!=2]
    

提交回复
热议问题