/* * Copyright 2008-2013 NVIDIA Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include THRUST_NAMESPACE_BEGIN namespace detail { namespace static_map_detail { template struct key_value { static const unsigned int key = k; static const unsigned int value = v; }; template struct cons { template struct static_get { static const unsigned int value = (key == Head::key) ? (Head::value) : Tail::template static_get::value; }; template __host__ __device__ static unsigned int get(unsigned int key) { return (key == Head::key) ? (Head::value) : Tail::template get(key); } }; template struct cons { template struct static_get { static const unsigned int value = (key == Head::key) ? (Head::value) : default_value; }; template __host__ __device__ static unsigned int get(unsigned int key) { return (key == Head::key) ? (Head::value) : default_value; } }; template struct static_map { typedef cons< key_value, cons< key_value, cons< key_value, cons< key_value, cons< key_value, cons< key_value, cons< key_value, cons< key_value > > > > > > > > impl; template struct static_get { static const unsigned int value = impl::template static_get::value; }; __host__ __device__ static unsigned int get(unsigned int key) { return impl::template get(key); } }; } // end namespace static_map_detail template struct static_map : static_map_detail::static_map< default_value, key0, value0, key1, value1, key2, value2, key3, value3, key4, value4, key5, value5, key6, value6, key7, value7 > {}; template struct static_lookup { static const unsigned int value = StaticMap::template static_get::value; }; template __host__ __device__ unsigned int lookup(unsigned int key) { return StaticMap::get(key); } } // end namespace detail THRUST_NAMESPACE_END