mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 01:20:06 +00:00 
			
		
		
		
	AWS Level 2 Provider FindKey
This commit is contained in:
		
							parent
							
								
									80310029e5
								
							
						
					
					
						commit
						bde8d288bd
					
				
					 5 changed files with 90 additions and 1 deletions
				
			
		
							
								
								
									
										41
									
								
								wxdata/include/scwx/util/map.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								wxdata/include/scwx/util/map.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,41 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <map> | ||||
| #include <optional> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace util | ||||
| { | ||||
| 
 | ||||
| template<class Key, class T> | ||||
| std::optional<T> GetBoundedElement(std::map<Key, T>& map, Key key) | ||||
| { | ||||
|    std::optional<T> element = std::nullopt; | ||||
| 
 | ||||
|    // Find the first element greater than the key requested
 | ||||
|    auto it = map.upper_bound(key); | ||||
| 
 | ||||
|    // An element with a key greater was found
 | ||||
|    if (it != map.cend()) | ||||
|    { | ||||
|       // Are there elements prior to this element?
 | ||||
|       if (it != map.cbegin()) | ||||
|       { | ||||
|          // Get the element immediately preceding, this the element we are
 | ||||
|          // looking for
 | ||||
|          element = (--it)->second; | ||||
|       } | ||||
|    } | ||||
|    else if (map.size() > 0) | ||||
|    { | ||||
|       // An element with a key greater was not found. If it exists, it must be
 | ||||
|       // the last element.
 | ||||
|       element = map.rbegin()->second; | ||||
|    } | ||||
| 
 | ||||
|    return element; | ||||
| } | ||||
| 
 | ||||
| } // namespace util
 | ||||
| } // namespace scwx
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat