xref: /AOO42X/main/sw/source/filter/ww8/needed_cast.hxx (revision 0cd1d3bc037f5a786106de8ee49650b4f01d26ae)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef WW_NEEDED_CAST_HXX
25 #define WW_NEEDED_CAST_HXX
26 
27 #include <tools/debug.hxx>
28 #include "staticassert.hxx"
29 
30 namespace ww
31 {
checking_cast(Param in,Ret)32     template<typename Ret, typename Param> Ret checking_cast(Param in, Ret)
33     {
34         return static_cast<Ret>(in);
35     }
36 
checking_cast(Ret in,Ret)37     template<typename Ret> Ret checking_cast(Ret in, Ret)
38     {
39         DBG_ASSERT( false, "UnnecessaryCast" );
40         return in;
41     }
42 
43     /*
44     needed_cast is the same as static_cast except that there will be a compile
45     time assert when NDEBUG is not defined and the in and out types are the
46     same. i.e. needed_cast catches unnecessary casts
47     */
needed_cast(Param in)48     template<typename Ret, typename Param> Ret needed_cast(Param in)
49     {
50         /*
51         Massage a single argument and a ret value into two arguments to allow
52         a determination if the dest type is the same as the source type
53         */
54         return checking_cast(in, Ret());
55     }
56 }
57 #endif
58 
59 /* vim: set noet sw=4 ts=4: */
60