在编译时获取文件字符串

时间:2018-07-31 16:40:48

标签: c++ macros c++14 compile-time

file1.cc

export function fetchPosts(subreddit) {
  return async (dispatch) => {
    dispatch(requestPosts(subreddit));
    let json;
//  ^^^^^^^^
    try {
      const response = await fetch(`https://www.reddit.com/r/${subreddit}.json`);
      json = await response.json();
    } catch (error) {
      console.log('An error occurred.', error);
      return;
    }
    dispatch(receivePosts(subreddit, json));
  }
}

file2.cc

this.selector.select2({
     minimumInputLength: 2,
     ajax: {
         url: function(param){return 'http://localhost:3000/suggestions?&'},
         dataType: 'json' ,
         data: function (params) {


      var query = {
       search: params.term,
      }
      return query;
    },
          processResults: function(data) {
            var results = []; 
            $.each(data, function (index, search) {
                 results.push({
                     id: search.id,
                     text: search.val
                 });
             });

             return {
              "results":results
             };                            
         },

     },

     width: 'resolve',
  }); 

所以,我需要的是void func() { std::cout << "test\n"; } 编译时而不是执行时间中将file1.cc的内容作为字符串。

如何实现此GET_FILE宏?

0 个答案:

没有答案