The class boost::date_time::special_values_parser has a method named likely. However, I am using this class in code that uses likely/unlikely as branch-prediction macros (see How do the likely/unlikely macros in the Linux kernel work and what is their benefit?). Is there a way to still use this code while also using the macros?
            Asked
            
        
        
            Active
            
        
            Viewed 144 times
        
    0
            
            
         
    
    
        jhourback
        
- 4,381
- 4
- 26
- 31
1 Answers
4
            
            
        Is there a way to still use this code while also using the macros?
Yes. Function-like macros require () immediately to expand, regular functions don't. Workaround:
(boost::date_time::special_values_parser::likely)( /* ... */ );
 
    
    
        Aykhan Hagverdili
        
- 28,141
- 6
- 41
- 93
- 
                    That's a good way to call it, but unfortunately, just including the header file for `boost::date_time::special_values_parser` conflicts with the macro. – jhourback Mar 11 '21 at 18:15
- 
                    1@jhourback include the headers *before* defining macros. – Aykhan Hagverdili Mar 11 '21 at 18:16
- 
                    That could work, but it's tricky because the header is included by other headers, so I would have to mandate a specific order of header inclusion in other headers. (i.e., include the header that defines `likely` only after you include the header that includes `boost::date_time::special_values_parser`). – jhourback Mar 11 '21 at 18:19
- 
                    3@jhourback defining lower case macros with no prefix is the decision that led you to a name conflict, and this solution tries to mitigate that. The actual solution is to give the macros ugly names like `MY_LIB_LIKELY`. – Aykhan Hagverdili Mar 11 '21 at 18:20